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.
I think you got to do this, then it would kick chic!
.SortedColumns.Clear()
.ResetSortedColumns()
End With
Or Do this
Dim dtMytable = ctype(grdMyGrid.datasource, datatable)
Then sort table by using table.SELECT ...bla, bla
then call this line
grdMyGrid.UpdateData
I have not try second approache but I think it would work to
Hope this help
Hi Woody,
There's no way to get the original order back. The grid does not track this. You should submit a feature request to Infragistics.
Request a Feature or Component
Hi,
I have a similar question here. I am binding my WinGrid with a group of data from database, e.g ID, TextData. So there is no sorting order on textdata column and ID column was hiding from user. Now I allow user to click header of textdata column, so it will be sorted. But How can I do to let user go back to original order, which is sorted by ID, without reload the data again?
Thanks, Woody
Thanks for the help, the SortedColumns.RefreshSort() method is what i needed.
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();