Infragistics UltraGrid Group Changed Event

664 Views Asked by At

I have an Infragistics UltraGrid and I need to know when the user adds/removes a column grouping. I see there are events for when a row is collapsed/expanded and an event for when the grid's filter changes, but I don't see any events that would fire when a column grouping is added/removed. Does anyone know of an UltraGrid event that would fire at that point? If not, are there any workarounds I might be able to use to achieve this?

I've already tried using AfterBandHiddenChanged and AfterGroupPosChanged. Neither of those seem to do what I need.

I'm using Infragistics 11.2 CLR2.0 (I know it's quite out-of-date, but it's not my call to update it)

1

There are 1 best solutions below

0
starx207 On

After some digging and experimenting, I found a workaround. It's not the prettiest, but it gets the job done. If anyone has any better suggestions, I'm all ears. But here's what I came up with in case someone else is interested.

I utilize the grid's BeforeSortChanged and AfterSortChanged events. The "Before" event sets a flag to indicate whether the groupings have changed. The "After" event is where I perform the operation I need to perform if the flag was set to indicate that the groupings changed.

Here's the "Before" event:

private void Grid_BeforeSortChange(object sender, Infragistics.Win.UltraWinGrid.BeforeSortChangeEventArgs e) {
    int preSort = 0;
    int postSort = 0;

    // This set of sorted columns are the columns that were already sorted
    // before the sort change.
    foreach (var col in e.Band.SortedColumns) {
        if (col.IsGroupByColumn) {
            preSort++;
        }
    }

    // This set of sorted columns are the columns that will be
    // sorted after the sort change is applied
    foreach (var col in e.SortedColumns) {
        if (col.IsGroupByColumn) {
            postSort++;
        }
    }

    // Compare the number of grouped columns before the
    // sort to the number after the sort
    _groupingsChangedFlag = preSort != postSort
}

And here's the "After" event:

private void Grid_AfterSortChange(object sender, Infragistics.Win.UltraWinGrid.BandEventArgs e) {
    if (!_groupingsChangedFlag) {
        return;
    }
    // Groupings changed, so do some action
}