473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

SortCommand event not supported for Windows DataGrid?

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
1 1413
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
4
by: Steven | last post by:
Hi there, I am having a weird problem. I have a datagrid with both an ItemCommand and a SortCommand. It was working fine until a day ago. Now, whenever I click a column to fire the...
2
by: John Sturgeon | last post by:
Hello: When creating a dynamic datagrid (i.e. columns are not added until runtime), and enabling allow sorting, the SortCommand event is never fired. Anyone know why or a way around it? This is...
0
by: lien | last post by:
In march 23, 04. Steven Cheng showed us how to do sortcommand for datagrid created at run time (thank you) . What if I have mixed static and dynamic columns? that is colunms added into static...
5
by: Kurt Schroeder | last post by:
I'm using VS.net. I have created a component with the basic set of database commands. This component returns a record set that is bound to a datagrid. I want to add a dynamic sort, but am not sure...
2
by: Dexter | last post by:
Hello all, I have a problem with SortCommand event. When i click at a linkbutton with commandname property as "Sort", the postback is raised, but don't execute SortCommand. Somebody have any...
1
by: Alex Maghen | last post by:
I have a DataGrid on my ASPX and I'm confused about the interaction with the page based on whether the page is just loading or is being reloaded with a call to the SortCommand of the DataGrid: ...
3
by: Mark Gilkes | last post by:
Hi, I have an aspx page in which I am building a DataGrid control in the code-behind dynamically. The DataGrid is declared along with BoundColumns and bound to the datasource, then added to a...
2
by: Joey | last post by:
I have an asp.net 1.1 C# web application with a datagrid. I set the datagrid's "AllowSorting" property to "True". Then I created a sort function for it by selecting the datagrid in the designer,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.