Hi
In my application if I group my data on one columns say "Col1".Now I go and sort my data on the same column "Col1".
The resulting grid has all the groups collapsed, I want that it should maintain the same status as it has before applying sorting.
i.e if some groups are collapsed while others are expanded, so the resulttant grid (after sorting)should show the same .
Please suggest.
Regards
Deepti
deepti54, Thank you for your question. SharpGrid does not offer an inherent way to keep track of all columns expand / collapse states. The way to approach this would be through the use of some custom code (which saves the expand collapse state before the sort, and applies it to the grid after the sort).
The link below contains some information about Controlling Group Expansion/Collapse through Code.http://www.datadynamics.com/forums/78644/ShowPost.aspx
Please let me know if I can be of further assistance. Thank you!
I wrote a few procedures to persist and restore the grouped states. Hope this helps. Not sure why it was never incorporated into the control. When you sort on the grouped column or when you refresh a bound grid it loses the expand\collapsed states.
Hope this Helps....
Dim arExpanded() As String 'In General Declarations
Private Sub SGGrid1_BeforeClickSort(ByVal ColIndex As Long, CancelSort As Boolean)
If SGGrid1.Groups.Count = 0 Then Exit Sub 'I am only allowing grouping on one column at a time. You could iterate through the groups collection and check for match on the GroupingColumn If SGGrid1.Groups(1).GroupingColumn = SGGrid1.Columns(ColIndex).Key Then PersistGroupState End If End Sub
Private Sub SGGrid1_AfterClickSort(ByVal ColIndex As Long)
If SGGrid1.Groups.Count = 0 Then Exit Sub 'I am only allowing grouping on one column at a time. You could iterate through the groups collection and check for match on the GroupingColumn.
If SGGrid1.Groups(1).GroupingColumn = SGGrid1.Columns(ColIndex).Key Then RestoreGroupState SGGrid1.Redraw End If End Sub
Sub PersistGroupState()
Dim row As sgRow, i As Integer
Erase arExpanded
For Each row In SGGrid1.Rows If row.Type = sgGroupHeader Then If row.GroupHeading.Expanded Then i = i + 1 If i = 1 Then ReDim arExpanded(0) ReDim Preserve arExpanded(i) arExpanded(i) = NoNull(row.GroupHeading.GroupingValue) ' row.Key End If End IfNext
End Sub
Sub RestoreGroupState()
Dim row As sgRowDim i As Integer
On Error GoTo ErrorHandler
For i = 1 To UBound(arExpanded) For Each row In SGGrid1.Rows If row.Type = sgGroupHeader Then If NoNull(row.GroupHeading.GroupingValue) = arExpanded(i) Then row.GroupHeading.Expand End If End If Next Next
ErrorHandler:'Array Not initialized will generate an errorEnd Sub