SortCommand event not supported for Windows DataGrid?

J

James Ramaley

I am trying to use the DataGrid SortCommand event, but it is not
recognized by the IDE's syntax checker. The same applies for the
DataGridSortCommandEventArgs class. All the examples I found are
ASP.NET related, but no windows forms samples. What am I doing wrong?
In my windows app I just need to detect when grid column sorting
changes, so that I can restore it when the DataSource is replaced. Is
there an alternative way to do this?

thanks
 
K

Ken Tucker [MVP]

Hi,

Add a handler to the dataviews list changed event. If you are using
a datatable as the datasource use the datatable's defaultview list changed
event.

Dim ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strConn As String

Dim strSQL As String

Dim da, daEmployees As OleDbDataAdapter

Dim conn As OleDbConnection

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)

da.Fill(ds, "Categories")

daEmployees = New OleDbDataAdapter("Select * From Employees Order by
LastName, FirstName", conn)

daEmployees.Fill(ds, "Employees")

DataGrid1.DataSource = ds.Tables("Categories")

DataGrid2.DataSource = ds.Tables("Employees")

AddHandler ds.Tables("Employees").DefaultView.ListChanged, AddressOf
ListChanged

End Sub



Private Sub ListChanged(ByVal sender As Object, ByVal e As
System.ComponentModel.ListChangedEventArgs)

Dim hti As DataGrid.HitTestInfo

Dim pt As Point

pt = DataGrid2.PointToClient(Me.MousePosition)

hti = DataGrid2.HitTest(pt)

Trace.WriteLine(String.Format("Sort on column {0}", hti.Column))

End Sub



Ken
 

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