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
275
Wingrid Sorting
posted

Can someone provide me with a suggestion on how to handle sorting on the Wingrid?  Here is my scenario.  I'm populating the wingrid from a dataView that's derived programattically (i call a stored procedure, etc.).  Let's say we have State and County as fields for example.  In that stored procedure i sort by state ASC.  Suppose the user sorts by county then adds a record.  The new record shows up in the wrong place in the grid.  I would like to have the grid sort it in the correct place automatically when a record is added - according to whatever sorting criteria the user previously selected.  Additionally i would like to preset the sort indicator/etc. so that the correct column and direction show up initially (State and ASC in my case)

 I imagine it's a matter of recording the sort criteria somehow then resorting the underlying DataView object once my update/insertion is complete but i'm not sure.

Note that i do not make another call to the stored procedure so the initial sorting done in there should not matter.

 

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

     Hi,

        You can sort the column programmatically by setting the SortIndicator property on the grid column. Typically, you would do this in the InitializeLayout event. 

        If you are allowing the user to change the sorting and you want to save this, then You can use the Save* and Load* methods on the grid.Displaylayout to save all user-modifiable settings to a file.

        The grid does not automatically sort new rows because this might be weird for a user who enters a new row. It would be odd for the user to create a new row and then move off that row (which commits the row) and then to have that row suddenly jump to a new position and grid scroll.  But if you want to do this in code, you can force the grid to re-sort a single row by calling the RefreshSortPosition method on that row. If you are adding multiple rows and want to refresh the sort position of all rows, you can do it like so:

        this.ultraGrid1.DisplayLayout.Bands[0].SortedColumns.RefreshSort(); 

Children