Determine datagrid's currently sorted column

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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.
 
B

Brian Vallelunga

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
 

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

Top