Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
280
sorting grid doesn't sort datasource too
posted
anyone know how i can get my datasource (an array) to sort when the user sorts the grid? For example, if the user clicks the column header of my grid it DOES sort for them. However, if I try to access row five of my underling datasource array i.e. MyArray(5).PropertyName it won't necessarily be the same row because only the grid sorted not my array.
Parents
  • 469350
    Verified Answer
    Offline posted

    The grid deals with the data source via the BindingManager in DotNet, or the IList or IBindingList interfaces. None of these provide any support for sorting. Also, not every data source supports sorting and the ones that do don't neccessarily all do it the same way. So there's no way the grid can sort your actual data source for you. 

    So my first question is... why do you want to sort the data source? Even if the data source is sorted the same as the grid, you still can't really rely on an indices of the rows being the same, because you would have to account for filtering, too. And there would also be complications involved with child rows (assuming your data source is hierarchical). 

    If you just want to get the object in the data source that corresponds to a grid row, you can use the ListObject property on the row.

    Another option would be to handle events of the grid and try to match up the sorting in your data source. So you would handle the AfterSortChange event of the grid. 

Reply Children
No Data