I understand how the user can hold down shift to sort on multiple columns however our users want to sort by one column then the other instead of holding down shift. The arrows don't have to stay at the top. They want it to basically work like windows explorer does.
I See a couple notes in the forum about SortedColumns.add but I'm not sure if this is what I need.
Windows Explorer only sorts by a single column. If that's what you want, then you would set the HeaderClickAction to SortSingle instead of SortMulti.
ok, let me be more clear. I have a list of first and last names.
Last Name First Name
Doe John
Doe Abe
The users want to sort by first name, then sort by last name. So they click on first name then click on last name. The problem is the first name reverts back to the original sort when last name is sorted. Is there a way to do this without holding down shift?
There's nothing like that built-in to the grid.
You could probably handle the BeforeSortChanged event and examine the previous SortedColumns and the new one and then merge them rather than losing the original sort. But then how would the user ever turn sorting off?
Hi,
I am facing the same problem, can you please provide a sample code for "handling the BeforeSortChanged event".
I have a seperate button to clear the sort on the columns. Any help appreciated.
That's because I am adding the column back into the collection at the end.
Unfortunately, I don't see any way around this. I tried using Insert instead of Add, but the insert method doesn't have an overload that takes a SortDirection.
Setting the SortDirection after Inserting should work, but it doesn't because this causes the BeforeSortChange event to fire recursively. So at this point, I don't see any way to get this working correctly.
If you have not already done so, you should Submit a feature request to Infragistics
Your code worked for multi column sorting, however the sort order of the columns is messed up.
For example if i click on the "First Name" column first and then the "Last name". The grid sorts by the last Name and then the First Name.
Is there any way to do it so that the grid sort in the order it is clicked. In this example: The sort on the "first name" should remain and then it should sort by "last name".
Thanks,
Thanks for the code, that helped.
private void ultraGrid1_BeforeSortChange(object sender, BeforeSortChangeEventArgs e) { // Loop through the existing sorted columns. foreach (UltraGridColumn column in e.Band.SortedColumns) { SortIndicator originalSortIndicator = column.SortIndicator; switch (originalSortIndicator) { case SortIndicator.Disabled: case SortIndicator.None: // If the column was not already sorted, leave it alone. break; case SortIndicator.Ascending: case SortIndicator.Descending: SortIndicator newSortIndicator = e.SortedColumns.Exists(column.Key) ? e.SortedColumns[column.Key].SortIndicator : SortIndicator.None; // If the column was sorted, see what it's new state is. switch (newSortIndicator) { case SortIndicator.None: // This column went from sorted to unsorted. So keep it sorted. e.SortedColumns.Add(column, originalSortIndicator == SortIndicator.Descending); break; case SortIndicator.Disabled: // This should never happen since the user cannot sort a disabled column. break; case SortIndicator.Descending: case SortIndicator.Ascending: // This column was sorted and is still sorted (although the // direction may have changed), so leave it alone. break; } break; } } }