Hi,
Based on my understanding, you're using DataGrid control in a WinForms
application written in VS2005. You'd like to know during run-time whether
the DataGrid control is resorted and if yes, which column is sorted,
ascending or descending. If I'm off base, please feel free to let me know.
I have spent some time researching on this question, but unfortunately I
didn't find how to get the above information when I bind a
DataSet/DataTable to a DataGrid control. The DataGrid control doesn't
expose such properties for us to determine whether the DataGrid control is
resorted, which column is sorted and the sort order. The DataTable class
doesn't supply such properties either. I have tried to appeal to the
default view of the DataTable ( we could get the default view of a
DataTable through its DefaultView property). However, DataView only has a
Sort property which is used to sort the underlying data source by a certain
rule.
I have also tried to use a BindingSource as the data source of the DataGrid
control. I could get whether the DataGrid control is resorted by the
IsSorted property of the BindingSource. But BindingSource couldn't tell me
the further information ( which column is sorted and the sort order).
Since you're using VS2005, I recommend you to use DataGridView instead of
DataGrid. DataGridView is a new control shipped with VS2005, which has many
new features and is apt to extend.
The DataGridView class has SortedColumn and SortOrder properties. If
there's no sort in the DataGridView control, the value of the SortedColumn
property is Nothing; otherwise, it refers to the currently sorted column
and the SortOrder property tells us the sort order.
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.