473,614 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ 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.Dat aView dv = this.ds1.tableA .DefaultView;

dv.AllowNew = false; // no append row

dv.AllowDelete = false; // no delete row

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

dv.ApplyDefault Sort = false;

....

}
Also in the mouse down/up events:

{

....

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

DataGrid.HitTes tInfo hti = dataGrid1.HitTe st(pt);

if( hti.Type == DataGrid.HitTes tType.ColumnHea der )

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

base.OnMouseUp( e); // ... or OnMouseUp
}
Thanks in advance

Mike
Dec 13 '05 #1
2 14857
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.Dat aView 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.Dat aView dv = this.ds1.tableA .DefaultView;

dv.AllowNew = false; // no append row

dv.AllowDelete = false; // no delete row

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

dv.ApplyDefault Sort = false;

....

}
Also in the mouse down/up events:

{

....

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

DataGrid.HitTes tInfo hti = dataGrid1.HitTe st(pt);

if( hti.Type == DataGrid.HitTes tType.ColumnHea der )

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******@discu ssions.microsof t.com> wrote in message
news:27******** *************** ***********@mic rosoft.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.Dat aView 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.Dat aView dv = this.ds1.tableA .DefaultView;

dv.AllowNew = false; // no append row

dv.AllowDelete = false; // no delete row

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

dv.ApplyDefault Sort = false;

....

}
Also in the mouse down/up events:

{

....

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

DataGrid.HitTes tInfo hti = dataGrid1.HitTe st(pt);

if( hti.Type == DataGrid.HitTes tType.ColumnHea der )

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
1635
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 reading round the newsgroups, it seems that a custom 'IComparer' is the answer, but I'm not quite sure how to do this. Really, how to get at the IComparer that the DataGrid/DataView uses for sorting. Can anyone point me towards a nice example...
2
945
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 datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
3
3121
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 sorts twice because I inserted a messagebox in the dgMouse (MouseUp) event. Before ok is pressed, the table changes from the order it was loaded to ascending order. After ok is pressed, it goes to descending. The code is below. Any idea why...
7
2444
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 Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here
4
2107
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 codebehind file. I am using c#. Thanks Manny
5
2520
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 I cannot sort the data when I click on the column header. I have set the tablestype.allowsorting = true, but this has no effect.
8
15160
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 that seems to work for 99% of the cases where I need to disable datagrid column sorting: Private Sub datagrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagrid.MouseDown Dim pt As New Point(e.X,...
1
7116
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 the first column in the grid only. I havent found a way to reliably do this yet. I tried putting the following code in the datagrid's mouse down event Dim hti As DataGrid.HitTestInfo
0
2077
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 help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
0
8627
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7093
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5540
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4052
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
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 we have to send another system
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.