Determine datagrid's currently sorted column

  • Thread starter Thread starter Brian Vallelunga
  • Start date Start date
B

Brian Vallelunga

I need to figure out how, in code, to determine a bound datagrid's currently
sorted column and then to change it. The result will be used in a context
menu with an Arrange By -> list similar to Outlook.

Any ideas?

Brian
 
Hi Brian,

You can obtain the underlying System.Data.DataView through the corresponding
CurrencyManager's List property and the query the DataView for its Sort
property contents.
You will obviously get data column name with this approach, and I hope this
is what you really need. To change the sorting manually, you will probably
update the Sort property value with a new column name and sort sense.
 
Thanks. I think this will work, but it is a bit obtuse because of the table
style and DataGridColumnStyles I have setup that map field names to header
text. Question: is there an easy way, given a table style and a header text
of a column to get the underlying field name? And vise-versa: given a field
name, can I get the column style header text? Right now I have to loop to
find what I'm looking for and I think there must be an easier way.

Thanks again,

Brian



Dmitriy Lapshin said:
Hi Brian,

You can obtain the underlying System.Data.DataView through the corresponding
CurrencyManager's List property and the query the DataView for its Sort
property contents.
You will obviously get data column name with this approach, and I hope this
is what you really need. To change the sorting manually, you will probably
update the Sort property value with a new column name and sort sense.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Brian Vallelunga said:
I need to figure out how, in code, to determine a bound datagrid's currently
sorted column and then to change it. The result will be used in a context
menu with an Arrange By -> list similar to Outlook.

Any ideas?

Brian
 
Back
Top