|
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 If Next
End Sub
Sub RestoreGroupState()
Dim row As sgRow Dim 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 error End Sub
|