Hi,
I have a CheckBox to allow a user to select whether or not they would want a list to be auto sorted with the following in a CheckChanged event:
if (this.ultraCheckEditorAutoSort.Checked) {this.ultraGridUsers.DisplayLayout.Bands[1].SortedColumns.Clear();this.ultraGridUsers.DisplayLayout.Bands[1].SortedColumns.Add("Alias", false);this.ultraGridUsers.DisplayLayout.Bands[0].SortedColumns.Add("GroupID", false);}else{this.ultraGridUsers.DisplayLayout.Bands[1].SortedColumns.Clear();this.ultraGridUsers.DisplayLayout.Bands[1].SortedColumns.Add("AutoID", false);this.ultraGridUsers.DisplayLayout.Bands[0].SortedColumns.Add("AutoID", false);}
The problem is when I have it sorted and I add a new row, it will not be automatically sorted. It will work if you toggle off and on the AutoSort option (checkbox) again. My question is: is there a way to implement AutoSort automatically and/or is there a way to refresh the grid after I add a row?
Thanks in advance
Hello,
You probably have to Refresh the SortedColumns once you've changed the rows collection:
this.ultraGridUsers.DisplayLayout.Bands[Index].SortedColumns.RefreshSort(bool obj);
where the "obj" determine to re-group your ultraGrid or not.
Hope this helps.
Thanks for your reply. I tried to do that after I added a new row but it didn't seem to work.
Interestingly without that fix, the sorting seemed to work on Group 2 and on. Attached is a screen shot for reference. I want to sort it based on the first column.
I would like to also note, I'm adding the rows programatically and the "AfterRowInsert" event isn't firing.
My guess is that you are adding the rows to the DataSource and not to the grid. This means that the grid handles the notifications from the data source aschronously and if you refresh the sorting immediately after adding the row, the new row does not yet exist in the grid.
If that is the case, then you could get around it in a couple of ways. I'd recommend using the BeginInvoke method to call a method which refreshes the grid sorting. Invoking it instead of calling the Refresh directly should introduce enough of a delay for the grid to have received the notification and responded to it.
Another option would be to add the new row(s), then call the grid's Refresh method to force the grid to paint before you Refresh the sorted columns.
If none of that works, we would probably need to see a sample project demonstrating this behavior so we could check it out.
Regarding the AfterRowInsert, this event fires in response to user action. There's no reason for the grid to fire this event when you add a row to the data source in code. You don't need an event to tell you that this happened, bcecause you already know. :)