Hi..

Im using VS08 to build my C# App. Im using a MVP architecture & LINQ. I have populated my datagridview. but my problem is, i want to sort the columns in the grid view whenver i click on the header of the column. There is no property to do the same, so i just wanted to know how to achieve this programmatically or by any other possible way.

Thanks,

Recommended Answers

All 3 Replies

You can use the sort method to programmatically sort the DGV to a specific column.

DataGridView1.Sort(DataGridView1.Columns[0], ListSortDirection.Ascending);

hi..

i tried the same method.but the problem is, im using an object as its datasource.so may be thats why it needs some programming.

Does any1 know how to sort it when the data source is an object?

hi..

i tried the same method.but the problem is, im using an object as its datasource.so may be thats why it needs some programming.

Does any1 know how to sort it when the data source is an object?

Text from MSDN page:

The DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:

1. The IList interface, including one-dimensional arrays.

2. The IListSource interface, such as the DataTable and DataSet classes.

3. The IBindingList interface, such as the BindingList<T> class.

4. The IBindingListView interface, such as the BindingSource class.

Reference:

1. http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx
2. http://msdn.microsoft.com/en-us/library/ms171600.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.