Click here to Skip to main content
14,334,974 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello
When a column heading is clicked in a DataGridView, the default behavior is to order the grid rows based on the clicked column.I need to disable This..plz help
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this

foreach (DataGridViewColumn column in dataGridView.Columns)
{
    column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
   
Comments
ridoy 1-Aug-13 8:14am
   
good one,+5
ErBhati 1-Aug-13 9:13am
   
Where i put this code
in form_load it not works
Rate this:
Please Sign up or sign in to vote.

Solution 3

i found solutions

if (e.RowIndex >= 0)
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 4

If you can extend the DatagridView you can override the Sort method with am empty one. This disables Sort for the DatagridView entirely.
public override void Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction)
{
      //base.Sort(dataGridViewColumn, direction);
}

Note: You cannot even programmatically sort any column.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100