I have an UltraWinGrid that gets loaded with data every time the user clicks on a refresh button. The new data is loaded into the UltraWinGrid by setting the DataSorce member to a new DataTable each time.
The grid is set up to allow the user to group the columns, sort on columns, or filter data using any of the columns. I need to preserve the grouping, sorting, and filtering. I have succeeded at doing that using the following methods:
Private sortIndicator As List(Of Infragistics.Win.UltraWinGrid.SortIndicator) Private filterConditions As List(Of Infragistics.Win.UltraWinGrid.FilterConditionsCollection) Private isGroupByColumn As List(Of Boolean)
Private Sub GetFlatColumnSortOrder()
Dim columnCount As Integer = grdServer.DisplayLayout.Bands(0).Columns.Count If (columnCount > 0) Then sortIndicator = New List(Of SortIndicator)(columnCount) filterConditions = New List(Of Infragistics.Win.UltraWinGrid.FilterConditionsCollection) isGroupByColumn = New List(Of Boolean) For index As Integer = 0 To columnCount - 1 sortIndicator.Add(grdServer.DisplayLayout.Bands(0).Columns(index).SortIndicator) Dim columnFilterConditions As Infragistics.Win.UltraWinGrid.FilterConditionsCollection = grdServer.DisplayLayout.Bands(0).ColumnFilters(index).FilterConditions filterConditions.Add(columnFilterConditions) isGroupByColumn.Add(grdServer.DisplayLayout.Bands(0).Columns(index).IsGroupByColumn) Next index End If End Sub
Private Sub SetFlatColumnSortOrder() If (sortIndicator IsNot Nothing) Then Dim columnCount As Integer = grdServer.DisplayLayout.Bands(0).Columns.Count For index As Integer = 0 To columnCount - 1 If (isGroupByColumn(index)) Then Dim descending As Boolean = False If (sortIndicator(index) = Infragistics.Win.UltraWinGrid.SortIndicator.Descending) Then descending = True End If grdServer.DisplayLayout.Bands(0).SortedColumns.Add(grdServer.DisplayLayout.Bands(0).Columns(index), descending, True) End If grdServer.DisplayLayout.Bands(0).Columns(index).SortIndicator = sortIndicator(index) grdServer.DisplayLayout.Bands(0).ColumnFilters(index).ClearFilterConditions() For Each fc As FilterCondition In filterConditions(index) grdServer.DisplayLayout.Bands(0).ColumnFilters(index).FilterConditions.Add(fc) Next Next (index) grdServer.DisplayLayout.Bands(0).Groups.Clear() End If End Sub
GetFlatColumnSortOrder() gets called before the DataSource is set and SetFlatColumnSortOrder gets called after the DataSource is set.
Everything works fine except that the current state of the groups (whether or not they are open or closed in not being preserved. If groups are set up by the user and the user has opened them, then after the Refresh button is pressed, the columns to be grouped appear in the group box and all filters and column sorting orders are correctly preserved, but all the groups are closed (so the user has to click on the + signs in the tree to reopen the ones he wants to be opened.
How do I save and restore the status (open/closed) of the groups?
Thanks,
Andy
Hello Andy,
When you resting the data source of UltraGrid, this action also reset the layout of the grid. SO if you want to preserve the layour you could use Save()/SaveAsXML() methods to save current layout and Load()/LoadFromXML() methods to restore the layout (I suggest you to use this overloads that takes as second parameter ProperyCategory):
http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v12.2~Infragistics.Win.UltraWinGrid.UltraGridLayout~Save.html
http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v12.2~Infragistics.Win.UltraWinGrid.UltraGridLayout~SaveAsXml.html
http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v12.2~Infragistics.Win.UltraWinGrid.UltraGridLayout~Load.html
http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v12.2~Infragistics.Win.UltraWinGrid.UltraGridLayout~LoadFromXml.html
preserving the layout will not preserves row states (in other words this will not save expansion state of your groups). So you should manually iterate trough your groups and to populate collection with the expanded one before resetting data source and after you recover the layout to expand those groups that are in your collection.
Please let me know if you have any further questions.
I find when I query for the groups (which the user set up using the grouping box, the grid indicates there aren't any groups. I tried something like
grdServer.DisplayLayout.Bands(0).Groups (and there weren't any Groups defined)
I believe I was using the Groups property on the band to get this. The only way I could even discover anything about the user defined group was by querying the each Column by using the following code:
grdServer.DisplayLayout.Bands(0).Columns(index).IsGroupByColumn
I didn't see any means to get the opened/closed state of the group. How can I do that.
(My grid is getting loaded with data from a single table into Band(0)).