473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to sort a datagrid when clicking on column?

How do I enable my Windows Forms datagrid to sort when I click on the column
header? I have a collection of custom classes that are displayed in my
datagrid, and it works great except for this missing feature! AllowSorting
property is set to True, but it doesn't seem to do anything.

Thanks,
Jon
Nov 15 '05 #1
2 2153
Hi Jon,

Your collection class needs to implement IBindingList so the DataGrid will
know how to sort it. For the details check out this article:

Sorting the Unsortable Collection
http://msdn.microsoft.com/library/de...et01272004.asp

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:ed******** ******@TK2MSFTN GP10.phx.gbl...
How do I enable my Windows Forms datagrid to sort when I click on the column header? I have a collection of custom classes that are displayed in my
datagrid, and it works great except for this missing feature! AllowSorting
property is set to True, but it doesn't seem to do anything.

Thanks,
Jon

Nov 15 '05 #2
Thanks!

Jon

"Rob Windsor [MVP]" <rw******@NO.MO RE.SPAM.bigfoot .com> wrote in message
news:uo******** ******@TK2MSFTN GP09.phx.gbl...
Hi Jon,

Your collection class needs to implement IBindingList so the DataGrid will
know how to sort it. For the details check out this article:

Sorting the Unsortable Collection
http://msdn.microsoft.com/library/de...et01272004.asp
--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:ed******** ******@TK2MSFTN GP10.phx.gbl...
How do I enable my Windows Forms datagrid to sort when I click on the

column
header? I have a collection of custom classes that are displayed in my
datagrid, and it works great except for this missing feature! AllowSorting property is set to True, but it doesn't seem to do anything.

Thanks,
Jon


Nov 15 '05 #3

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

Similar topics

14
2079
by: Jack Kaufmann | last post by:
I am trying to verify a datagrid in which there must be an entry in both columns of any new row, and those values must be greater than the corresponding values in the previous row. It is pretty simple to verify the cell the user starts in by invoking a verifying event for the underlying textbox in that cell, but what I would like to do is to change the focus to the other column in the new row if it has not been filled in. If in handling...
3
4083
by: | last post by:
Is there an event that is invoked when a user sorts a column in a Windows Forms DataGrid? I have context senstive icons that are enabled\disabled depending upon the selected item in the datagrid. When I sort the datagrid the selected item changes. I can not find the event that is fired when the sorting occurrs therfore I cannot enable\disable the icons Thanks in advance,
7
2450
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
5
2224
by: Gene Hubert | last post by:
I'm using the DefaultView from the Datasource for a DataGrid to present the data in a particular order. It seems that sorting in this way is an "Active Sort", as is the default sort that is provided by clicking on a column header. By "Active Sort", I mean that editing a value in a sorted column may cause the record to be moved to maintain the sort order. Is there an efficient way to present the data in a given order but not have it be...
1
1454
by: Jim | last post by:
Hello, I am creating a windows form application using vb.net 2003 which displays data in a datagrid, and then, if the user wants, I produce a nicely formatted crystal report of the data. The question I have is: if I allow the user to sort the datagrid by clicking on the column header, is there any way that I can tell which column the datagrid is sorted on, so that I can sort the data in the crystal report the same way?
1
5307
by: nate axtell | last post by:
In VB .NET I load the contents of an Excel or comma seperated values file into a dataGrid (via a datatable). One of the columns has a comma in the name of the column. So for the comma separated values files I put double quotes are the column name. What I see is that the name ends up getting displayed correctly in the DataGrid column, "Class (1,2,3)". When I click on the column to sort I see the following error: "Additional information:...
4
2711
by: skOOb33 | last post by:
I successfully autosized the columns and rows on my Datagrid, and am now facing another issue. Having the sorting ability by clicking the column headers is key, but when I do that, it resizes all my rows back to their defaults. I populate the datagrid, resize it accordingly and it works fine...just when I click the headers is when it messes up. It would be fine if I could run my autosizing again after the sorting is done since there...
0
619
by: thomasp | last post by:
I have a datagridview that allows the user to sort the column by clicking on the header of the column the user wishes to sort. I did not code this, it had the ability when the datagrid was populated. My question is how can I chande the cursor to an hourglass when the user clicks the header and change it back to the default once the sort is accomplished. The database is large and the sort takes a few seconds. Need something to show the...
2
2924
by: thomasp | last post by:
I have a datagridview that allows the user to sort the column by clicking on the header of the column the user wishes to sort. I did not code this, it had the ability when the datagrid was populated. My question is how can I change the cursor to an hourglass when the user clicks the header and change it back to the default once the sort is accomplished. The database is large and the sort takes a few seconds. Need something to show the...
0
8397
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
8827
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
8503
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
8605
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...
1
6167
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
5632
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
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
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
2
1620
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.