How can I reset row grouping programmatically ? The following statement does nothing:
if (ultraGrid1.Rows.IsGroupByRows) ultraGrid1.DisplayLayout.ResetGroupByBox();
ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
ultraGrid1.DisplayLayout.Override.AllowGroupBy = DefaultableBoolean.True;
Thank for a hint
Kagel
What do you mean by "reset row grouping"?
If you mean that you want to programmatically ungroup any columns that were grouped, you can loop through all columns in all bands of your grid, and set the IsGroupByColumn property to false.
If you want to do this more efficiently, you can instead go through the SortedColumns collection on each band, and set IsGroupByColumn to false on each of these columns. You can do this because grouping by a column implicitly sorts it. If you do this, you should loop through the collection "backwards," since removing the grouping will modify the collection. Below is the approach I'd use (note that I haven't tested this so it may need further modification)
using Infragistics.Win.UltraWinGrid;...foreach (UltraGridBand band in grid.DisplayLayout.Bands){ for (int i = band.SortedColumns.Count - 1; i >= 0; i--) { UltraGridColumn col = band.SortedColumns[i]; col.IsGroupByColumn = false; }}
of course, I'm talking about to ungroup programmatically the rows
unfortunatly the property IsGroupByColumn' can't be set :
Error 1 Property or indexer 'Infragistics.Win.UltraWinGrid.UltraGridColumn.IsGroupByColumn' cannot be assigned to -- it is read only
Error 1 Property or indexer 'Infragistics.Win.UltraWinGrid.UltraGridColumn.IsGroupByColumn'
cannot be assigned to -- it is read only
there must be another way....?
How about band.SortedColumns.Clear()?
Yes that does ungroup the grid but it removes my column sorts.
I was trying to implement a views menu that would allow the user the ability to partially (and completely if they choose to) reset features of the grid like 'Remove all column filters, Restore default sort order, Restore all hidden columns' etc.
All those work but then I decided to give them an 'Unpivot grid' menu item.
I read on the forums how the mechanism behind grouping first sorts on the column and then groups ... which is why the clear sort you describe also ungroups but ... it hoses my users previous sorting (which does stay in place, when they group... I guess because it 'adds' that column to the sorted fields).
So do I have to track when they are 'just' sorting and keep those field's keys in a list versus sorting because they were grouping ...
then ungroup using the method you describe and re-sort based on my list?
Yikes.
I am getting dizzy just thinking about it :)
Thanks,
Mitch
Got doing something else...
Looked at it this morning and 'sussed it', as Zaphod would say.
This clears all Grouped columns and leaves my previous Sorts in place.
Private Sub tsmiViewUnpivot_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsmiViewUnpivot.Click 'un pivot the grid For Each band As Infragistics.Win.UltraWinGrid.UltraGridBand In uwgRequirements.DisplayLayout.Bands Dim i As Integer = band.SortedColumns.Count - 1 While i >= 0 Dim col As Infragistics.Win.UltraWinGrid.UltraGridColumn = band.SortedColumns(i) If col.IsGroupByColumn = True Then band.SortedColumns.Remove(band.SortedColumns(i).Key) End If i = i - 1 End While Next AdjustCheckedMenuItems() End Sub
Mmmm, not so much ambiguous as opening more options.
In the case you describe I would ask the customer what they felt they wanted it to do (keep their last sort of the column or back sorts made while grouped out)...
But I see what you are saying.
Thanks, Mike.
Mitchster
Hi MItchster,
Okay, I didn't realize you were trying to make a distinction between sorting via clicking on the column header and sorting by grouping. When you group a column, it is sorted first and the grid has no reason to keep track of why it was sorted, only that it is.
So you are correct that if you want to separate the two operations, you would have to jump through some hoops. You could probably use the BeforeSortChange event to detect the individual changes to the SortIndicator, the IsGroupByColumn or both.
But what you are describing seems a little ambiguous to me. For example, suppose a user sorts a column. Then he groups a column (which sorts that column ascending). Then he clicks on the GroupBy header to sort that column descending?
Would you maintain the descending sort on that grouped column when you ungroup or discard it?
If you would want to keep it, then why not keep the ascending sort when they ungroup?
If you would not want to keep it, then why not simply discared the sorting from any grouped columns when you ungroup?
You often start your replies like that ... hmmm.
You have a good grasp of what I am trying to do and yes I would, as I said, have to do all that you describe ...
but I would also have to somehow track the sorting that was applied by 'column header clicking' versus the sorting that was applied when a column header was dragged to the top to group.
Then I would have to use that list of keys to do the 'pre-grouping' re-sort.
Seems to me (and I may be out there) that this is some functionality that should be built in...
Hooked into the 'grouping part of the model' where there is currently only a read only field:
col.IsGroupByColumn
Your control should handle the part of the 'finagling' we both described that is required to do programmatic ungrouping and maintain previous sort values.
But hey, who am I to say.
:)
Hi Mitch,
I'm not exactly sure what you are trying to do.
But the sorting and grouping are tightly tied together and they are both handled by the SortedColumns collection on the band.
So if you want to ungroup, but still maintain the same sort order, what you would have to do is clear the SortedColumns, then re-sort the columns the way they were. So you would need to loop through the collection and record the column key and the column.SortIndicator. Then clear the collection. Then use the key and the SortIndicator to re-apply the sorting.