Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView Sorting
 

DataGridView Sorting

I have a Datatable, it is binded with DatagridView in .net 2.0. I need to do custom sorting only Datagridview's Data( not Data table). How do I implement this?

please send Details ASAP

Elango1  Tuesday, October 03, 2006 1:47 PM

The easiest way is to use a BindingSource. Set the BindingSource.DataSource property to your DataTable, then set DataGridView.DataSource to the BindingSource. You can then use the BindingSource.Sort property to sort.

To elaborate, the DataGridView does not store a separate copy of the data that it is bound to, so any sorting must take place in the data source. You cannot sort a DataTable, however. All DataTable sorting takes place in a DataView, which you can retrieve through the DataTable.DefaultView property or create a new DataView and pass the DataTable to its constructor. When you use a BindingSource, all of that happens automatically.

Karl Erickson  Tuesday, October 03, 2006 5:28 PM
I have done exactly that to bind generic Lists to the DataGridView. But the problem is when we add a DataTable to the BindingSource, DataGridView sorts fine. When we add a generic list, wich holds custom business objects, that is for example a List<Customer>, to the binding source the DataGridView doesn't sort.

Any idea what is missing here?

Thanks in advance.
Guganeshan Thambiraja  Friday, November 02, 2007 1:38 PM

You can use google to search for other answers

Custom Search

More Threads

• Events from one form executing on another form?
• ToolStripItem DataBinding
• DatagridviewComboBox Datatype
• Getting Dataset information behind Datagrid Row
• Using an Access database hosted @ IIS
• binding datagrid view to another data grid view
• Datagridview, coloring the row
• DataGrid Performance
• DataGrid saving modified cell values?
• set value to GridView row