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

DataGrid - can you tell what column is currently used foir the sort?

P: n/a
Jim
Hello,

I am creating a windows form application using vb.net 2003 which displays
data in a datagrid, and then, if the user wants, I produce a nicely
formatted crystal report of the data.

The question I have is: if I allow the user to sort the datagrid by
clicking on the column header, is there any way that I can tell which column
the datagrid is sorted on, so that I can sort the data in the crystal report
the same way?

I have not been able to find anything which tells me the current sort for
the datagrid, nor can I figure out how to override the header column click
so that I can set a variable in it...

Any help would be appreciated!

Thanks!

Jim
Nov 21 '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

------------------------
"Jim" <jr@nospam.wi.rr.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello,

I am creating a windows form application using vb.net 2003 which displays
data in a datagrid, and then, if the user wants, I produce a nicely
formatted crystal report of the data.

The question I have is: if I allow the user to sort the datagrid by
clicking on the column header, is there any way that I can tell which column
the datagrid is sorted on, so that I can sort the data in the crystal report
the same way?

I have not been able to find anything which tells me the current sort for
the datagrid, nor can I figure out how to override the header column click
so that I can set a variable in it...

Any help would be appreciated!

Thanks!

Jim

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.