473,376 Members | 1,216 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,376 software developers and data experts.

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.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, e.Y)
Dim hti As DataGrid.HitTestInfo = dgACE.HitTest(pt)

If hti.Type <> DataGrid.HitTestType.ColumnHeader Then
MyBase.OnMouseDown(e)
End If
End Sub

However, this code does not work when my datagrid resides on a user
control. The datagrid_MouseDown 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 15118
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 "automatically" without doing
any of these things.
<si***********@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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, e.Y)
Dim hti As DataGrid.HitTestInfo = dgACE.HitTest(pt)

If hti.Type <> DataGrid.HitTestType.ColumnHeader Then
MyBase.OnMouseDown(e)
End If
End Sub

However, this code does not work when my datagrid resides on a user
control. The datagrid_MouseDown 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.googlegr oups.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 "datagridname." 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 "SortCommand" (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.googlegr oups.com...
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.
What kind of DataSource are you using because i can't reproduce the problem.
Setting DataGrid.AllowSorting to false does seem to work, but if you use
DataGridTableStyle(s) then you must set the relevant
DataGridTableStyle.AllowSorting 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_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles datagrid.MouseDown
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = dgACE.HitTest(pt)

If hti.Type <> DataGrid.HitTestType.ColumnHeader Then
MyBase.OnMouseDown(e)
End If
End Sub

However, this code does not work when my datagrid resides on a user
control. The datagrid_MouseDown 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*********************@g49g2000cwa.googlegro ups.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
DataGridTableStyle.AllowSorting 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
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...
3
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...
2
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:...
6
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
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
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...
1
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...
2
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...
3
by: Bruno Neves Pires Silva | last post by:
Hello, Programmers. How can I disable sorting in a DatagridView? Thanks in advance.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.