ListChanged event?

G

Guest

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.
 
G

Guest

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_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
Dim HTI As DataGrid.HitTestInfo = DataGrid1.HitTest(e.X, e.Y)
Select Case HTI.Type
Case DataGrid.HitTestType.ColumnHeader
Dim ColName As String =
DataGrid1.TableStyles(0).GridColumnStyles(HTI.Column).MappingName
Dataview1.sort = ColName
Case ...
End Select
End Sub


www.charlesfarriersoftware.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top