How to undo AutoSizeRows on C1FlexGrid?

891 Views Asked by At

I am trying to achieve wrapping and unwrapping of text in C1FlexGrid columns in a menu click event handler. The below code works to wrap the text when appropriate menu action is selected. But how I can unwrap the text?

Me.Styles(C1.Win.C1FlexGrid.CellStyleEnum.Normal).WordWrap = True
Me.AllowResizing = AllowResizingEnum.Rows
Me.AutoSizeRows()

I tried the below code but it did not make any difference. Any help is appreciated. Thank you!

Me.Styles(C1.Win.C1FlexGrid.CellStyleEnum.Normal).WordWrap = False
Me.AllowResizing = AllowResizingEnum.None
Me.AutoResize = False
1

There are 1 best solutions below

0
On

You will need to loop round all the rows in the grid and set the height to -1. This will set them back to the default height.

You could create an extension method to toggle between auto-sized row heights that will allow the word-wrapping or default height rows.

<Extension()>
Public Shared Sub AutoSizeRows(ByVal grid As C1FlexGridBase, ByVal reset As Boolean)
    If grid Is Nothing Then
        Throw New ArgumentNullException(NameOf(grid))
    End If

    If Not reset Then
        grid.AutoSizeRows()
        Return
    End If

    For rowIndex As Integer = 0 To grid.Rows.Count - 1
        grid.Rows(rowIndex).Height = -1
    Next
End Sub

Then call grid.AutoSizeRows() to increase the row height to allow wrapped text and grid.AutoSizeRows(True) to reset the rows back to their default height.