Programmatically choose sort expression of datagrid

V

Vincent Vinet

Hi,
I probably overlooked this in the property pages, but I am trying to set
a sort expression programmatically for a datagrid to have it ordered in
reverse chronological order (there is a time column).
Now, the data does not come directly from a query, so I cannot just add an
order by to it...
is there any other way to do this then manually sorting the contents
everytime the grid`s content changes, while keeping the user from changing
that sort expression?
Thanks in advance
 
B

Bart Mermuys

Hi,

Vincent Vinet said:
Hi,
I probably overlooked this in the property pages, but I am trying to
set
a sort expression programmatically for a datagrid to have it ordered in
reverse chronological order (there is a time column).
Now, the data does not come directly from a query, so I cannot just add an
order by to it...

Yes, but how did you bind it ? If it is bound to a
DataSet/DataTable/DataView then you can sort it this way :

dataGrid1.AllowSorting = false;
CurrencyManager cm =
(CurrencyManager)BindingContext[dataGrid1.DataSource,dataGrid1.DataMember ];
DataView dv = (DataView)cm.List;
dv.Sort = "YourTimeColumnName DESC";

If it is bound to a (custom) collection you have to sort that collection.

HTH,
Greetings
 
V

Vincent Vinet

Ah, so I must sort the datatable! Thank you!

Bart Mermuys said:
Hi,



Yes, but how did you bind it ? If it is bound to a
DataSet/DataTable/DataView then you can sort it this way :

dataGrid1.AllowSorting = false;
CurrencyManager cm =
(CurrencyManager)BindingContext[dataGrid1.DataSource,dataGrid1.DataMember ];
 

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