Saturday, July 4, 2009

Sort on Multiple Columns in DataGridView

By default DataGridView supports Single Column Sort only.

To sort on multiple columns, we can use the following methods:


For Bounded DataGridview

1. Use Sort Method of DefaultView Property


DataView view = dt.DefaultView;
view.Sort = "C2 ASC, C3 ASC";
bindingSource.DataSource = view;


For UnBounded DataGridview

We need to do Custom Sorting

1. Using the SortCompare event

2. Sort(IComparer) overload of the Sort method for greater sorting flexibility

Same article available under http://www.dotnetspider.com/resources/29470-Sort-Multiple-Columns-DataGridView.aspx

No comments:

Post a Comment