Windows Datagrid Column Sorting

  • Thread starter Thread starter Carl Tribble
  • Start date Start date
C

Carl Tribble

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
 
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(myGridsDataSourceTable).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
 
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.DataSource,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
 
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
 

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

Back
Top