Reputation: 2517
I have a DataGridView that is bound to a DataTable, is there a way to reorder the rows in the DataGridView and have the changes reflected in the bound DataTable?
Upvotes: 0
Views: 2609
Reputation: 292405
Use a DataView
or a BindingSource
between the DataTable
and the DataGridView
, they both have a Sort
property :
DataView view = new DataView(table);
view.Sort = "Name ASC, Age Desc";
dataGridView.DataSource = view;
You can also filter the results using the DataView.RowFilter
property (or BindingSource.Filter
).
The DataGridView
will automatically reflect the changes
Upvotes: 1