473,757 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable Sorting in VB.NET

I thought the only thing I had to do to disable column sorting in
VB.NET was to set datagrid.AllowS orting = 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_MouseD own(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles datagrid.MouseD own
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTes tInfo = dgACE.HitTest(p t)

If hti.Type <> DataGrid.HitTes tType.ColumnHea der Then
MyBase.OnMouseD own(e)
End If
End Sub

However, this code does not work when my datagrid resides on a user
control. The datagrid_MouseD own event is triggered but sorting still
occurs for the column. It's critical that I disable sorting in the
datagrid due to the other things I am trying to do with the datagrid.

I'm about ready to pull my hair out trying to figure this one out so
any suggestions on how to resolve this issue would be greatly
appreciated!

Thank you!

Joy

Dec 7 '05 #1
8 15167
This problem sounds very strange since the DEFAULT of a DataGrid is NO
SORTING. In other words, you must change a property value AND write code in
the DataGrid's SortCommand event handler as well as define the sort criteria
for each column of the DataGrid for sorting to work.

I find it hard to believe that you get sorting "automatica lly" without doing
any of these things.
<si***********@ yahoo.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
I thought the only thing I had to do to disable column sorting in
VB.NET was to set datagrid.AllowS orting = 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_MouseD own(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles datagrid.MouseD own
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTes tInfo = dgACE.HitTest(p t)

If hti.Type <> DataGrid.HitTes tType.ColumnHea der Then
MyBase.OnMouseD own(e)
End If
End Sub

However, this code does not work when my datagrid resides on a user
control. The datagrid_MouseD own event is triggered but sorting still
occurs for the column. It's critical that I disable sorting in the
datagrid due to the other things I am trying to do with the datagrid.

I'm about ready to pull my hair out trying to figure this one out so
any suggestions on how to resolve this issue would be greatly
appreciated!

Thank you!

Joy

Dec 7 '05 #2
When I talk about sorting, I am referring to the ability to click on a
datagrid columnheader and sort the specified column by ascending or
descending order.

I can tell you that I have no SortCommand event handlers whatsoever and
perhaps it is strange that it is happening by default but for whatever
reason that is what is happening. I wouldn't have posted this question
if I was experiencing what you are suggesting.

But perhaps I can use the SortCommand event handler to disable this
functionality.

Dec 7 '05 #3
What EXACT control are you using (Windows or Web Form DataGrid)?
What Framework/VS.NET are you talking about?

In VS.NET 2003 (Framework 1.1), there are 3 things that must be done to get
a Web Form DataGrid to sort (and none of these are done by default):

The DataGrid must have its EnableSort property turned on (default is off).
The columns to be sortable, must have a sort field specified (not done by
default).
The DataGrid's SortCommand event must contain the code that actaully
performs the sort (not done by default).

This is all I can tell you. Good luck.
<si***********@ yahoo.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
When I talk about sorting, I am referring to the ability to click on a
datagrid columnheader and sort the specified column by ascending or
descending order.

I can tell you that I have no SortCommand event handlers whatsoever and
perhaps it is strange that it is happening by default but for whatever
reason that is what is happening. I wouldn't have posted this question
if I was experiencing what you are suggesting.

But perhaps I can use the SortCommand event handler to disable this
functionality.

Dec 7 '05 #4
I am using the Windows DataGrid with VS.NET 2003.

1. First, when I type "datagridna me." the intellisense does not display
the EnableSort property you mention. (fyi. I create a new instance of
a datagrid by simply dragging and dropping it from the Toolbar onto the
form.) So I have no idea where this mysterious property you speak of
resides. There is an AllowSorting property I mentioned previously but
like I said, it seems to sort no matter if this property is set or not.
In fact, when I search for "datagrid EnableSort" in the VS.NET help
topics, it returns 0 topics. Neither can I find anything in
www.msdn.com on "datagrid EnableSort" - I am still wading through the
results for "datagrid sort" and haven't found anything yet. So if you
could refer me to some documentation on "EnableSort " I would greatly
appreciate it.

2. Second, I looked and I can find no handler or overridable event
method called "SortComman d" (or by any other name for that matter) for
the datagrid.

3. Third, the previous code I mentioned to disable the sorting
functionality of a VB.NET datagrid did not come out of my own head. I
found it in google groups. So if what you are saying is true, why
wouldn't they have simply set EnableSort = false? Therefore I have a
feeling that I am not alone when it comes to trying to disable the
sorting functionality.

If anyone else has any suggestions or has encountered a similar problem
I would greatly appreciate any suggested fixes! Thank you.

Joy

Dec 7 '05 #5
When I did some more searching I was able to find the SortCommand for
the WebControl datagrid - however, I am working with the Windows Forms
datagrid and that method does not exist for that control.

Dec 7 '05 #6
Hi,

<si***********@ yahoo.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
I thought the only thing I had to do to disable column sorting in
VB.NET was to set datagrid.AllowS orting = False. Unfortunately this
has never worked for me.
What kind of DataSource are you using because i can't reproduce the problem.
Setting DataGrid.AllowS orting to false does seem to work, but if you use
DataGridTableSt yle(s) then you must set the relevant
DataGridTableSt yle.AllowSortin g to false.

HTH,
Greetings
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_MouseD own(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles datagrid.MouseD own
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTes tInfo = dgACE.HitTest(p t)

If hti.Type <> DataGrid.HitTes tType.ColumnHea der Then
MyBase.OnMouseD own(e)
End If
End Sub

However, this code does not work when my datagrid resides on a user
control. The datagrid_MouseD own event is triggered but sorting still
occurs for the column. It's critical that I disable sorting in the
datagrid due to the other things I am trying to do with the datagrid.

I'm about ready to pull my hair out trying to figure this one out so
any suggestions on how to resolve this issue would be greatly
appreciated!

Thank you!

Joy

Dec 7 '05 #7
Yes, that's why I asked. Sorry, I don't have any info. on the Windows Forms
DataGrid.
<si***********@ yahoo.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
When I did some more searching I was able to find the SortCommand for
the WebControl datagrid - however, I am working with the Windows Forms
datagrid and that method does not exist for that control.

Dec 7 '05 #8
Thanks Bart - that did the trick! I was neglecting to set the
DataGridTableSt yle.AllowSortin g to False, I was only doing it for the
datagrid. Thanks a lot! I'm glad it was such a simple fix!

Joy

Dec 7 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1654
by: Ross | last post by:
The following codes originally provided by a kind responder Toby A Inkster in another newsgroup for working on displaying a table on web capable of sorting are modified by me (a newbie). How to disable sorting by say, length and chart (last few codes at the end)? I find the order is important to display so cannot just single them out. <?php function insert_datatable_cmp ($a, $b) { return ($a]<$b]) ? -1 : 1; }
3
1357
by: Bill Nguyen | last post by:
I found that rows in datagrid can be sorted by clicking on the column header. However, this doesn't refresh the .currentindex DataGrid1.CurrentCell.RowNumber I need either to disable colum sorting programmatcially or somehow refresh the DataGrid1.CurrentCell.RowNumber index so that it will reflect the correct rownumber.
2
14869
by: Mike | last post by:
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: {
6
7217
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
3
14753
by: joey.powell | last post by:
Does anyone know how to disable sorting in a datagridview? I mean, when a user clicks a column header, the rows should not reorder.
1
7138
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
1
9690
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using a DataGridView on a Form. I want to disable the clicking on the columns headers to disallow the sorting. How can I do that, but without deriving the DataGridView? Is there any other way to disable the sorting of the DataGridView without deriving it?
2
2632
by: L. Kliemann | last post by:
* Jerry Coffin <jcoffin@taeus.com>: My question was mostly out of curiosity. I've been working with C++ for about half a year now, and I came across several occasions where my first approach was to use polymorphism, but it did not work (could not write compilable code that would express what I meant). In many of these cases, using templates was a solution. In fact, I cannot recall any major issue where polymorphism was a
3
7800
by: Bruno Neves Pires Silva | last post by:
Hello, Programmers. How can I disable sorting in a DatagridView? Thanks in advance.
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10069
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...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
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...
1
7285
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
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();...
3
3395
muto222
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.