Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sort column in DataGridView numerically in unbound mode

Posted on 2006-07-12
6
Medium Priority
?
504 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 380 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 120 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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 …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

927 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