Hi everybody. I am using the event AfterSortChange to handle the sort click on a specific column of my UltraGrid.Unfortunately I am using also the group by function when I prepare the layout of my grid, here:
private void InitializeGridLayout(object sender, InitializeLayoutEventArgs e){ e.Layout.Bands[0].SortedColumns.Add("Status", false, true);}
So, if a user click on the 'Description' column, when I use the AfterSortChange, if I want to know which column was clicked I use this code:
var columns = e.Band.SortedColumns;
But in this case it returns more than a column and honestly I don't know which one is the one he clicked, because the group by varies on-fly.
Do you suggest a better approach? I also need to know the order type 'asc' or 'desc'.
For now I have to keep in consideration all the columns sorted, also the ones in the group header, because my paging system will show, otherwise, part of the grouped columns in the first page and part in another one. I came out with this 'dirty' but functional solution:
private void AfterSortChange(object sender, BandEventArgs e) { var columns = e.Band.SortedColumns; var sortString = string.Empty; if (columns != null && columns.Count > 0) { foreach (UltraGridColumn column in columns) { sortString += string.Format( "{0} {1}, ", mapGridKeyToColumnName(column.Key), column.SortIndicator == SortIndicator.Ascending ? "ASC" : "DESC"); } sortString = sortString.Remove(sortString.LastIndexOf(",")); } }
I don't think there's any way to tell exactly what changed just from the AfterSortChange event. What you would have to do is record the sorting that exists in the band in the BeforeSortChange event and then compare the new sorted columns with the old ones in AfterSortChange.
You can tell if a column is grouped, though, by checking e.Band.SortedColumns[x].IsGroupByColumn
Thank you for the answer.
I was expecting to find something like that because is the specific column that you click which raises the event SortChanged so I was expecting in somehow to find that column somewhere in the eventargs, I also checked the sender, but is not the column clicked but the entire grid.