Hi there,
Is there any way to determine inside BeforeSortChange whether the event is raised because user is sorting by a column or grouping by a column?
The reason I need this distinction is because I need to cancel sorting inside BeforeSortChange when user single-clicks a column header and only allow it when user double-clicks the header. I'm setting a flag inside DoubleClickHeader and manually manipulating e.Header.Band.SortedColumns inside.
Unfortunately, when a user drags a column header into Group By area above, BeforeSortChange is also raised. If I cancel the event, the grouping is also canceled.
Any help is gladly apreciated.
-olf.
It seems like the DoubleClickHeader event isn't fired for the GroupByButtonUIElement, likely since this isn't truly acting as a header in this case. Fortunately, you can trap the DoubleClick event of the grid and see if it was a GroupByButtonUIElement:
private void ultraGrid1_DoubleClick(object sender, EventArgs e){ UIElement element = this.ultraGrid1.DisplayLayout.UIElement.LastElementEntered; GroupByButtonUIElement groupButtonElem = element.GetAncestor(typeof(GroupByButtonUIElement)) as GroupByButtonUIElement; if (groupButtonElem != null) { // Sort here }}
-Matt
Hi Matt,
Thanks for the solution. The drag&drop grouping works well. However, I can't seem to get the sorting working when a user double-clicks on a grouped column header inside the "Group By" area above the grid.
Is there a way to make a distinction between whether the user double-clicked on a grouped column header above all the headers or not? It seems DoubleClickHeader event is not raised in this situation.
Thanks,
One way to handle this would be to loop through the SortedColumns to see if any of them are GroupByColumns (through the IsGroupByColumn property). When you do this, you need to distinguish on whether the grouped column was there or not, however:
private void ultraGrid1_BeforeSortChange(object sender, Infragistics.Win.UltraWinGrid.BeforeSortChangeEventArgs e){ bool isGroupByOperation = false; foreach (UltraGridColumn column in e.SortedColumns) { // Check to see if the column already exists in the band's SortedColumns collection // since this means that the grouping has already taken place if (column.IsGroupByColumn && (!e.Band.SortedColumns.Exists(column.Key) || // If we've already sorted by the column, but not grouped, it will already // be in the collection so we need to check this too !e.Band.SortedColumns[column.Key].IsGroupByColumn)) { isGroupByOperation = true; break; } } // Now do a search to see if the columns are being un-grouped. // Only continue the search if we haven't found a GroupByColumn yet, for efficiency if (!isGroupByOperation) { foreach (UltraGridColumn column in e.Band.SortedColumns) { if (column.IsGroupByColumn && (!e.SortedColumns.Exists(column.Key) || !e.SortedColumns[column.Key].IsGroupByColumn)) { isGroupByOperation = true; break; } } } if (!isGroupByOperation) { // Check other flag here and cancel event if necessary }}