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

Windows Datagrid Column Sorting

P: n/a
After a user has clicked a column header to sort, how can I tell which
column header he clicked? In other words, how can I tell what order the
list is in after user changes it by clicking a column header?

Thanks,
-Carl
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
jim
Hey Carl,

the way this actually works is that when you bind to a datatable/dataset the
grid actually binds to the DefaultView property of the datasource. So, when
you click on the clolumnheaders, the sort property of this underlying
DefaultView is reset (based on which header you click).

that is the long of it just to give you an understanding of how the datagrid
works...

the short answer is to use the bindingcontext. something like...

ctype(me.myDataGrid.BindingContext(myGridsDataSour ceTable).Current,
DataRowView).Row

this line will get you the actual datarow that is currently selected in the
grid, regardless of the sort. (beware typos, it's late...)

hope this helps,

jim

"Carl Tribble" <ca*********@sbcglobal.net> wrote in message
news:eg*************@TK2MSFTNGP10.phx.gbl...
After a user has clicked a column header to sort, how can I tell which
column header he clicked? In other words, how can I tell what order the
list is in after user changes it by clicking a column header?

Thanks,
-Carl

Nov 21 '05 #2

P: n/a
If you want to know which column is sorted, I think you can retrieve the
dataView.Sort property for the DataView associated with your datagrid. You
can get this dataview through the CurrencyManager.

Dim cm as CurrencyManager =
CType(Me.DataGrid1.BindingContext(Me.DataGrid1.Dat aSource,Me.DataGrid1.DataM
ember), CurrencyManager)
Dim dv as DataView = CType(cm.List, DataView)
' dv.Sort should hold the sorted column(s)

=============
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Carl Tribble" <ca*********@sbcglobal.net> wrote in message
news:eg*************@TK2MSFTNGP10.phx.gbl...
After a user has clicked a column header to sort, how can I tell which
column header he clicked? In other words, how can I tell what order the
list is in after user changes it by clicking a column header?

Thanks,
-Carl

Nov 21 '05 #3

P: n/a
Thanks Clay, that is exactly what I was looking for.

Thanks also to Jim, your input was useful too.

I have only been using this newsgroup a short time, but I love it!

-Carl
"ClayB [Syncfusion]" <cl***@syncfusion.com> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
If you want to know which column is sorted, I think you can retrieve the
dataView.Sort property for the DataView associated with your datagrid. You
can get this dataview through the CurrencyManager.

Dim cm as CurrencyManager =
CType(Me.DataGrid1.BindingContext(Me.DataGrid1.Dat aSource,Me.DataGrid1.DataM ember), CurrencyManager)
Dim dv as DataView = CType(cm.List, DataView)
' dv.Sort should hold the sorted column(s)

=============
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

"Carl Tribble" <ca*********@sbcglobal.net> wrote in message
news:eg*************@TK2MSFTNGP10.phx.gbl...
After a user has clicked a column header to sort, how can I tell which
column header he clicked? In other words, how can I tell what order the
list is in after user changes it by clicking a column header?

Thanks,
-Carl


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.