views:

649

answers:

2

What is the proper method to tell a DataGridView to stop sorting?

I have a "screen" where I tell the grid programatically to sort by column 4 and ascending. When I switch to another area I want the same grid to come in 'default'/no sort. I'm removing all the columns and adding new ones. The sort remains on the 4th column.

I don't see a way to do this with the Sort() method. Any ideas?

+1  A: 

From MSN Forums:

The DataGridView is bound to a DataView and not the Table directly, so you need to set:

DataTable.DefaultView.Sort = String.Empty

Effectively clearing the sorting on the table and thereby the grid that is bound to it. This appears to require a Refresh of the DataGridView, unless you are using 2005, and then you can use a separate binding manager.

Joshua Drake
+1  A: 

I've accessed the sort on the BindingSource directly:

((BindingSource)_dgv.DataSource).Sort = string.Empty;

Ken