Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
285
Grouping by column causes SortChange
posted

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.

Parents
  • 37774
    Verified Answer
    posted

    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
        }
    }

    -Matt

Reply Children