By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

SortCommand event not supported for Windows DataGrid?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

------------------------

"James Ramaley" <jr******@iname.com> wrote in message
news:f8**************************@posting.google.c om...
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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.