I want to resort my grid when items in the datasource are changed (it's a bindinglist). Calling RefreshSort after I've made modifications works fine, but it seems that using RefreshSortPosition might be a more effective/performant call. However, I'm not sure how to determine the best way to get the affected rows. I don't want to make changes to support using RefreshSortPosition only to have those changes be more expensive than the gains I make by calling it. I thought I could wire to an event on the binding source or grid, but I didn't see an event that seemed appropriate.
Any best practice suggestions on this?
Hi,
RefreshSortPosition is for cases where you know that all of the rows are already sorted and you just need to refresh the position of a single row. So if you know you just added a new row to your data source, it would be more efficient to find that corresponding row in the grid (which would presumably be at the end of the rows collection) and refresh the sort position of that one row.
The same goes for a row where a value changed in a cell whose column is currently sorted.
RefreshSort re-sorts everything. So this is best to use only when you cannot determine the row(s) that may have changed.
In my case I don't know what rows I'm updating, I only know what objects in the binding source I'm updating.
I have one object which is manipulating the binding source and is ignorant of the presentation details, and another (the user control) which has wired up a grid to the binding source. I understand that I could wire up the user control to either the binding source or the grid, but I'm not sure which object/event is the most appropriate to use.
I think you are probably better off using RefreshSort, then.
You could try handling the IBindingList notifications from your data source or from the BindingManager and then attempting to find the corresponding row in the grid so you can refresh just that one row.
But I'm not entirely sure this would work reliably, because you can never be sure if you get the notification before or after the grid got it. And if you get it first, then the refresh of the sorting might not work, since the grid will not have the new data, yet. Although, I could be wrong about this.
Another consideration is that the in order to find the right row in the grid, the grid will have to iterate over the rows collection, anyway. So it probably would not gain you all that much performance.
Ok, thanks.