To sort a dataview, set the dataview.sort property to the mapping name of the
column that you want to sort on. When the user clicks on a column header,
get the mapping name and pass it to the sort property.
You can use sort using multiple columns separated by commas, and you can set
each column to ASC or DESC, with ASC as default.
dataview.sort = "colA"
OR
dataview.sort = "colA, colB DESC"
Also, getting the column name can be a little tricky. I found this code in
a recent project. It assumes you are using TableStyles and ColumnStyles. If
not, you could set up an association of datagrid column indices and dataview
column names with an ArrayList and alter the code below.
Private Sub DataGrid1_Mouse Down(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles DataGrid1.Mouse Down
Dim HTI As DataGrid.HitTes tInfo = DataGrid1.HitTe st(e.X, e.Y)
Select Case HTI.Type
Case DataGrid.HitTes tType.ColumnHea der
Dim ColName As String =
DataGrid1.Table Styles(0).GridC olumnStyles(HTI .Column).Mappin gName
Dataview1.sort = ColName
Case ...
End Select
End Sub
www.charlesfarriersoftware.com
"John" wrote:
When sorting a datagrid by clicking its column header, a ListChanged event is
raised by the dataview on that the datagrid is based. However, inside the
ListChanged event handler, I loop through the dataview and see that the order
of the dataview is not changed.
I have a SequenceNumber column in that dataview and wish to reset the column
when the datagrid is sorted. I don't want to loop through the datagrid, it's
slow.
Any suggesstions, thanks.