471,350 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Disable datagrid sorting

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
Dec 13 '05 #1
2 14686
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
"Mike" wrote:
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

Dec 13 '05 #2
Works! Thanks Ivan.

"Ivan Wong" <Iv******@discussions.microsoft.com> wrote in message
news:27**********************************@microsof t.com...
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
"Mike" wrote:
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

Dec 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chris Mayers | last post: by
3 posts views Thread by melanieab | last post: by
7 posts views Thread by DC Gringo | last post: by
4 posts views Thread by Manny Chohan | last post: by
5 posts views Thread by DKC | last post: by
8 posts views Thread by simchajoy2000 | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.