Programmatically choose sort expression of datagrid

  • Thread starter Thread starter Vincent Vinet
  • Start date Start date
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
 
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
 
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 ];
 
Back
Top