473,471 Members | 4,629 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 14834
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: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.