473,226 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 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 14811
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris Mayers | last post by:
I have a Windows Forms DataGrid that has a DataView as a datasource. My problem is that I want the datagrid to exhibit some special sorting properties when the header rows are clicked on. From...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
3
by: melanieab | last post by:
Hi, I'm programatically sorting in a datagrid. When a column header is clicked, the sort happens twice for some reason, making it looks like it only sorts in descending order. I can tell it...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
4
by: Manny Chohan | last post by:
hi guys, my code is returning an array and i need to create datagrid so that i can have sorting and implement prev....next function on it to navigate. is there any way this can be done in...
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
8
by: simchajoy2000 | last post by:
I thought the only thing I had to do to disable column sorting in VB.NET was to set datagrid.AllowSorting = False. Unfortunately this has never worked for me. I discovered another set of code...
1
by: ECD | last post by:
Hello all, I can usually find solutions to my .NET problems by searching these groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0 framework). I want to disable sorting on...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.