|
Many times users want to control the state of a group's expansion or collapse through code. To achieve this functionality, you can step through each row and check to see if it is a sgGroupHeader. In the following code, we check the GroupHeading GroupingValue to see if it matches the GroupingValue of a GroupHeading we want to collapse. Dim row As SGRowsize=2 'Step through each row in the grid For Each row In SGGrid1.Rows 'Check if the row is a sgGroupHeader If row.Type = sgGroupHeader Then 'Check if the current row's GroupingValue is one we want collapsed If row.GroupHeading.GroupingValue = "Print" Then 'Collapse the group row.GroupHeading.Collapse End If End If Next SGGrid1.Redraw This next approach resembles the first. However, here we do not check the GroupingValue, but choose to expand or collapse the GroupHeading based on the GroupingColumn. Dim row As SGRow 'Expand all groups so we can collapse only the groups that meet our criteria SGGrid1.ExpandAll 'Step through each row For Each row In SGGrid1.Rows 'Check if the row is a sgGroupHeader If row.Type = sgGroupHeader Then 'Check if the current row's GroupingColumn is Account If row.GroupHeading.GroupDef.GroupingColumn = "Account" Then 'Collapse the group row.GroupHeading.Collapse End If End If Next SGGrid1.Redraw The attached sample demonstrates how both approaches can be used to expand or collapse GroupHeadings through code. If you have any questions or need assistance, please feel free to submit a support request.
Applies To: SharpGrid 2.0
|