Hi,
We allow our users to select columns by which to group a grid. We need to save their choice so as to be able to re-instate it later (automatically).
Could you please let me know how to programmatically (C#) retrieve columns by which a grid is currently grouped, and also how to programmatically group a grid by some columns? We use WinForms UltraWinGrid and WPF XamGrid, and I would really appreciate if you could provide code samples for both of them.
Thank you.
Best regards,
Adam
Hi Adam,
I don't know anything about the XamGrid. But for the WinForms grid, grouping is tightly tied to sorting. So what you do is loop through the SortedColumns collection on the band and check the IsGroupBy property on the column.
To group a column, you use the SortedColumns.Add method. Use the overload that takes three parameters. The last param is a bool which indicates whether to group by the column.
Hi Mike,
Thank you for the reply. I tried the solution suggested by you and it works fine if there is a single GroupBy column. However, with two GroupBy columns I keep getting the following exception:
Unable to cast object of type 'Infragistics.Win.UltraWinGrid.UltraGridRow' to type 'Infragistics.Win.UltraWinGrid.UltraGridGroupByRow'
I catch the exception and the grid does end up showing two GroupBy columns. I tried enforcing execution on the UI thread (grid.Invoke) but the exception persisted. Should I just ignore it?