Datagrid sorting programatically - How?

  • Thread starter Thread starter Junkguy
  • Start date Start date
J

Junkguy

Hi all,

I need some advice on how to sort the contents of a datagrid from code. The
issue I have is a client that wants the datagrid to show its rows in "entry"
order (i.e. the order in which rows appear in the database) after performing a
new search to find some rows. This is actually how a datagrid will initially
show its rows, but after the user clicks a column header, the datagrid will
forever after show rows sorted according to that column.

There seems to be no way to get back to the "entry" order after that. I need a
way to reset the default ordering from the code, so that each search the user
does will revert to the unsorted display. Looking in the datagrid
documentation provides no help at all. In my particular usage, I have the
datagrid tied to a dataset.

Thanks to any who can help.
 
Junkguy said:
I need some advice on how to sort the contents of a datagrid from code.

Ok, nevermind I got it:

Datagrid dg;
...
DataTable dt = (DataTable) dg.DataSource;
dt.DefaultView.Sort = "";


At least it seems to work. Somebody let me know if this is a bad idea.

Thanks.
 
Back
Top