Reputation: 2491
DGV has no AllowSort property.
How can I prevent user to sort the items?
Upvotes: 1
Views: 1287
Reputation: 945
Set the sort value programmatically:
this.dataGridView1.Columns["Priority"].SortMode = DataGridViewColumnSortMode.NotSortable;
or for the whole DataGrid (I am on my mac and dont have my VM MS Machine up so something like):
foreach(dataGridView.Columns x in this.dataGridView1.Columns)
{
x.SortMode = DataGridViewColumnSortMode.NotSortable;
}
http://msdn.microsoft.com/en-us/library/8b9k0ktw.aspx
Upvotes: 1
Reputation: 116127
This thread describes some possible solutions:
Use the ColumnAdded
event:
private void MyDGV_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
{
e.Column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
Override OnColumnAdded:
protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
{
base.OnColumnAdded(e);
e.Column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
Upvotes: 0
Reputation: 4866
Loop over gridview columns and set the SortMode
of each column as this -
DataGridViewColumnSortMode.NotSortable
You can also do this via Designer
:: Go to Columns
collection > Set SortMode as NotSortable
Upvotes: 0