Solved

Sort column in DataGridView numerically in unbound mode

Posted on 2006-07-12
6
498 Views
Last Modified: 2008-02-26
I have added a column to an unbound DataGridView in VS2005 and need to have the column sort "numerically". I have used this line of code:
DataGridViewItems.Columns(0).ValueType = System.Type.GetType("System.Int32")
which does indeed seem to change the property, but it still sorts the columns "alphabetically". How can I accomplish this?

Bruce Mutch
0
Comment
Question by:bmutch
  • 3
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
vadim63 earned 95 total points
ID: 17096151
Why "DataGridViewItems"? This code works perfectly:

Me.DataGridView1.Columns(0).ValueType = System.Type.GetType("System.Int32")
0
 
LVL 10

Expert Comment

by:vadim63
ID: 17096160
And another thing. You have to set the ValueType before you put any data in.
0
 

Author Comment

by:bmutch
ID: 17096434
that is the same as the code I am using, and I am setting it before I put any data in, and it is still not sorting correctly ( numerically), (i.e.) 9999 is appearing before 27895 when I sort descending.

This column is a "link" column if that makes any difference.

0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 10

Expert Comment

by:vadim63
ID: 17096492
Sorry, no idea. The code, I posted shows me correct sorting. i.e.
1
3
11
22
0
 
LVL 8

Assisted Solution

by:kaliyugkaarjun
kaliyugkaarjun earned 30 total points
ID: 17097718
Hi


This link might help u

http://www.codeproject.com/aspnet/elphGrid.asp

Use int instead of String in the following expression .

 dt.DefaultView.Sort=(string)
                   this.ViewState["_orderBy"].ToString()+" ASC";
0
 

Author Comment

by:bmutch
ID: 17103621
ok found the problem,
for some crazy reason I had just copied over this code and did not change it:

row.CreateCells(DataGridViewItems, .Item("OrderNum").ToString().Trim() ...


of course adding the ToString... messed it all up.

Thanks to both. Since vadim63 had more respnses I'll give him the majority of the points.

Bruce
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LINQ - C# to VB convertion 12 56
Get hold of longitude and latitude in iframe string 11 45
Write to a printer using vb.net 9 23
vb.net class 3 11
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question