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
Sorry, but I don't quite understand. I have a number of columns, for example user id, session id, program id, and program name.
We allow the users to drag columns headers into the group by box so group the rows. There is a refresh button on the screen to get an updated list of sessions.
Every time the button is pressed the list of rows loaded into the grid can be very different, but the users want the groups they set up to be preserved and the expansion of those groups to be preserved. (We also allow sorting and filtering on all the columns).
The code above will save and restore the sorting, filtering, and columns that have been chosen on which to group, but I still don't understand how to save and restore the state (open or closed of the groups). I can iterate through the rows and get the values for the columns that the user has set up for grouping and build a collection of the combinations of those values and then for each one store the IsExpanded value. That seems like more work than I would expect to be necessary.
I suspect that I don't have the correct mental model of how this aspect of the grid works. Is there some collection that I can access which holds all the groups which the rows are divided into along with the values on which the group corresponds to? I was looking for some property on the band or on the row collection object,
Thanks for you great tech support. I appreciate how you guys respond so quickly to my questions.
The Groups property on the band refers to groups of columns. OutlookGroupBy, which groups the rows, is completely different and unrelated to that.
The Groups you are talking about here are rows - or, more specifically, GroupByRows.
So if you want to loop through the groups and determine which are expanded, you would loop through the grid.Rows collection and examine the Expanded property on the grid. You may also want to cast the UltraGridRow into an UltraGridGroupByRow so that you can access the row's Value and/or column for information on the grouping.
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)).
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.