Sorting datagrid entries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When using a DataGrid I can easily sort the items by clicking on the column
header, but is there a way to sort them automatically? If I have 20 records,
each numbered 1 to 20, and delete number 13 before adding it again, it
appears at position 20. Is there any way of getting the data to sort itself
when the form loads? Or, as I am using an XML file as the source of the
data, can that be sorted?
 
For a Windows Forms DataGrid, if your grid's datasource is a DataTable, you
can cause the grid to display things sorted by a column, say "Col1", by
setting the Sort property on the DefaultView.

this.datatable1.DefaultView.Sort = "Col1";

==========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Thanks ClayB, that's solved the problem.

ClayB said:
For a Windows Forms DataGrid, if your grid's datasource is a DataTable, you
can cause the grid to display things sorted by a column, say "Col1", by
setting the Sort property on the DefaultView.

this.datatable1.DefaultView.Sort = "Col1";

==========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Back
Top