Disable datagrid sorting

M

Mike

Hi,

I would like to disable sorting in a winform datagrid when a column header
is clicked.
The following does *not* seem to disable sorting and clicking the column
header still sorts the grid:

After loading data into the dataset:

{
....
this.dataGrid1.DataSource = this.ds1.tableA;

System.Data.DataView dv = this.ds1.tableA.DefaultView;

dv.AllowNew = false; // no append row

dv.AllowDelete = false; // no delete row

dv.Sort = ""; // no sort string <------- ????

dv.ApplyDefaultSort = false;

....

}


Also in the mouse down/up events:

{

....

Point pt = new Point(e.X, e.Y);

DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);

if( hti.Type == DataGrid.HitTestType.ColumnHeader )

return; // don't sort: don't call baseclass !!!

base.OnMouseUp(e); // ... or OnMouseUp
}


Thanks in advance

Mike
 
G

Guest

Have you set the AllowSorting property in the DataGrid class to false ??
e.g.

this.dataGrid1.DataSource = this.ds1.tableA;
this.dataGrid1.AllowSorting = false;
System.Data.DataView dv = this.ds1.tableA.DefaultView;
....
....
....

Hope it helps,
Ivan Wong
 
M

Mike

Works! Thanks Ivan.

Ivan Wong said:
Have you set the AllowSorting property in the DataGrid class to false ??
e.g.

this.dataGrid1.DataSource = this.ds1.tableA;
this.dataGrid1.AllowSorting = false;
System.Data.DataView dv = this.ds1.tableA.DefaultView;
...
...
...

Hope it helps,
Ivan Wong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top