Posted 14 January 2022, 3:58 am EST
Good day,
Is there an easy way in VB to show a large text wrapt in the cell. if possible the row should also fit to show all the text wraped. If needed scrollbar. can be used.
Best regards
Said
Forums Home / ComponentOne / WinForms Edition
Posted by: saidnai on 14 January 2022, 3:58 am EST
Posted 14 January 2022, 3:58 am EST
Good day,
Is there an easy way in VB to show a large text wrapt in the cell. if possible the row should also fit to show all the text wraped. If needed scrollbar. can be used.
Best regards
Said
Posted 17 January 2022, 3:08 am EST
Hi Said,
here is a snippet of code:
Dim cellStyleWrapped As CellStyle = Me.c1Flexgrid.Styles.Add("Wrapped", Me.c1Flexgrid.Styles.Normal)
cellStyleWrapped.WordWrap = True
Me.c1Flexgrid(row, col) = "Long text which should wrap"
Me.c1Flexgrid.SetCellStyle(row, col, cellStyleWrapped)
Me.c1Flexgrid.AutoSizeRows()
Best regards
Wolfgang
Posted 17 January 2022, 3:25 am EST
Hi Said,
As Wolfgang suggested, you can show Large text wrapped in cells, by setting the WordWrap property of the CellStyle to true.
To auto adjust the Row size to show full wrapped text, you can use the C1FlexGrid.AutoResizeRows method.
Kindly refer to the documentation links below for more information regarding the property and method mentioned above.
https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.C1FlexGrid.4.5.2~C1.Win.C1FlexGrid.CellStyle~WordWrap.html
https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.C1FlexGrid.4.5.2~C1.Win.C1FlexGrid.C1FlexGrid~AutoSizeRows.html
Regards
Avnish
PS: Thank You! Wolfgang, for the assist.
Posted 17 January 2022, 6:27 am EST
Dear Wolfgang, Dear Avnish,
The code from Wolfgang is Tip Top :).
Thanks to all and Best regards
Said
Posted 23 February 2022, 5:17 am EST
Dear Wolfgang, Dear Avnish,
After having many data in the table. I do the remark that the Wrap function took a long time to be finished after loading the Flexgrid. Is there a psooibiltiy to Wrap the Text during the loading of the Flexgrid.
Here the code that i use:
Sub
Dim Odbcda As New Odbc.OdbcDataAdapter(“SELECT VText FROM TableName ORDER BY VText”, connectionString9)
odbcDataSet = New DataSet
Odbcda.Fill(odbcDataSet, “VTextListe”)
Dim dt As DataTable = odbcDataSet.Tables(“VTextListe”)
DGI.DataSource = dt
With DGI
.Cols(1).Caption = “Text”
.Cols(1).Width = 270
'.Cols(1).StyleDisplay.WordWrap = True 'is not working
End With
WrapCellVText()
End Sub
Sub WrapCellVText()
Try
Dim cellStyleWrapped As CellStyle = Me.DGI.Styles.Add(“Wrapped”, Me.DGI.Styles.Normal)
cellStyleWrapped.WordWrap = True
Dim rw As Integer = 0
For Each r As Row In DGI.Rows
If rw = 0 Then
Else
Me.DGI.SetCellStyle(rw, 2, cellStyleWrapped)
Me.DGI.AutoSizeRows()
End If
rw += 1
Next
Catch ex As Exception
MsgBox("Error ‘WrapCellVText’ : " & vbCrLf & ex.ToString, MsgBoxStyle.Critical)
End Try
End Sub
Best regards
Said
Posted 23 February 2022, 6:12 am EST
Hi Said,
there are two improvements:
a) before the call to “WrapCellVText()”, make a call to “DGI.BeginUpdate()”, and after thid method, call “DGI.EndUpdate()”
b) in your loop, you call “AutoSizeRows”, for EACH row in the grid. This calculates the row height for the full grid very often. Use “AutoSizeRow (rw)” instead to autosize only the current row.
Best regards
Wolfgang
Posted 23 February 2022, 6:20 am EST
Dear Wolfgang,
It make sense to me and sounds logic waht you said.
AutoSizeRow (rw) is working so quick and perfectly.
Respect :)[ul][/ul]
Best regards
Said
Posted 25 February 2022, 1:31 am EST
Hi,
As suggested by Wolfgang, in your loop, you should use the AutoSizeRow() method instead of the AutoSizeRows() as the AutoSizeRows resizes all the rows of the Grid, and you are calling the method in every iteration of your loop. Kindly refer to the following links for more information about these methods.
https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.C1FlexGrid.4.5.2~C1.Win.C1FlexGrid.C1FlexGrid~AutoSizeRow.html
https://www.grapecity.com/componentone/docs/win/online-flexgrid/C1.Win.C1FlexGrid.4.5.2~C1.Win.C1FlexGrid.C1FlexGrid~AutoSizeRows().html
Also, you can refer to the following link on Improving the performance of the FlexGrid, which suggests different ways to optimize your grid for the best performance of your application.
https://www.grapecity.com/componentone/docs/win/online-flexgrid/improve-performance.html
Let us know if you need any other information.
Regards.
Avnish