Question how to disable column tab in datagridview

aronmatthew

Member
Joined
Aug 5, 2019
Messages
19
Programming Experience
Beginner
a very annoying problem when working with datagridview is accidently pressing the column tab which changes the order of the data in the grid. i would very much like to to disable that feature or at least override it with my own sort method. i have tried the following with no effect:
foreach (DataGridViewColumn c in dataGridView1.Columns)
{
column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
 
How exactly are the columns being created? Have they been created in the designer or are they auto-generated when you bind data or something else? If you created them in the designer, set that property in the designer too. If they are auto-generated then the code you have should work but it obviously needs to be executed after binding, so that the columns actually exist.
 
Back
Top Bottom