January
30
2009
3:18 pm
Tags:
Post Meta :
You Diggin?

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;
}

October
15
2009
8:36 am
Type:
Comment
Emyu

Good one. better than looping through columns - which in any case won’t work if grid columns are added and removed dynamically

Participate! Leave your comment.