We have an UltraGrid bound to an UltraDataSource. We programmatically add rows to the data source by creating a new UltraDataRow, setting a tag on the new row, then using UltraDataRowsCollection.Add() to add the new row to our rows collection. Subsequently, our CellDataRequested event handler is invoked, whereupon we use the tag set on the row earlier to look up the data for the row.
Our problem is this: new rows added in this way always appear at the bottom of the grid, irrespective of any sort order the user has selected by clicking on column headings. After new rows have been added, I can click again on column headings and the sort order is enforced correctly. I need my new rows to appear in the correct part of the grid, according to the sort-order currently in force. How can I make that happen?
Thanks!
Hi,
This behavior is intentional. The grid doesn't automatically sort new or modified rows because it might be weird for the user to add or edit a row and then have that row move to a new position in the grid.
If you want to force a row to move to the proper sort order, you can call RefreshSortPosition on the individual grid row, or calling Refresh on the SortedColumns collection of the band to re-sort everything.
Thanks for the reply Mike. What you say makes perfect sense.
In the meantime I had arrived at a solution that (for us) is better: -
When adding a new row I call SetCount on the UltraDataRowsCollection to increase the row count by one, and push the id of my data item into a queue. In the event handler for CellDataRequested, if the data row has a null Tag, I pull the next data item id from my queue, tag the row, and use that data item to supply the data for the row.
I hope that makes sense. It certainly seems to work well for me, and sorting behaves as normal. If there's a nasty gotcha waiting in there, I hope you'll let me know, otherwise I hope this post might help others in future.
Thanks again.