Solved

Sort column in DataGridView numerically in unbound mode

Posted on 2006-07-12
6
496 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now