DataGridView has column sorting enabled by default. It’s usually a good thing but in some rare cases it can be a problem and should be disabled. To disable it, add a ColumnAdded event:
this.dataGridView1.ColumnAdded += new System.Windows.Forms.DataGridViewColumnEventHandler( this.dataGridView1_ColumnAdded);
and add a function to disable the sorter on the column which is being added like this:
private void dataGridView1_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
{
dataGridView1.Columns[e.Column.DisplayIndex].SortMode = DataGridViewColumnSortMode.NotSortable;
}
Good one. better than looping through columns – which in any case won’t work if grid columns are added and removed dynamically
Thanks, glad it helped
Thanks a lot.
Was looking all over for this.