This is a migrated thread and some comments may be shown as answers.

Is there a way to sort (numeric) strings like numbers?

9 Answers 2445 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nadine
Top achievements
Rank 1
Nadine asked on 19 Mar 2009, 03:27 PM
Hello,

I have a TextColumn in my grid that contains numeric data.

I don't want to change it to a DecimalColumn...

When I sort, it's sorted only concerning the first digit, because it is text.

Is there a way to convert it to numeric data for sorting in my Sorting Expressions?

If not: How can I add an empty value to a DecimalColumn by using a value Array?

Best regards.

Nadine

9 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 23 Mar 2009, 07:22 PM
Hi Nadine,

The easiest way to do this is to set the DataType property of your column to int. Here is  a sample:

 
this.radGridView1.Columns["Value1"].DataType = typeof(int); 
 

If you have other questions, don't hesitate to ask.

All the best,
Jack
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nadine
Top achievements
Rank 1
answered on 24 Mar 2009, 07:58 AM
Hello,

thank you for your reply.

Desperately this doesn't seem to change the sorting behavior.

The column is always sorted like this (first character/number):

112
113
114
2
295
3
35
...

Best regards

Nadine
0
Jack
Telerik team
answered on 24 Mar 2009, 06:01 PM
Hello Nadine,

Thank you for your response.

This code should be working. Could you please open a support ticket and send me your application? I will try to locate the issue and find a proper solution. In case you do not have access to the support ticketing system, please ask the purchase holder in your company to add you as a License Developer to the purchase your company holds. More information on License Developers you can find here: http://www.telerik.com/account/faqs.aspx


Regards,
Jack
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Ruth Goldberg
Top achievements
Rank 1
answered on 09 Mar 2010, 03:59 PM
I'm having a similar problem. The key field for my grid is an integer and the data type of the column shows as Int32. It displays as right justified. If I leave sorting as none, since it is the key column, I'll see a numeric sort. But if I set the sorting property of the column to Ascending, I get an alphabetic sort, not a numeric sort, where 1670 comes before 768.  My problem is when adding records. With no sort, they are shown at the bottom, instead of in their correct place.
0
Jack
Telerik team
answered on 10 Mar 2010, 01:15 PM
Hi Ruth Goldberg,

That's strange. Does the work around with changing the DataType property of the column help? If not please send me your application and I will check the issue. I am looking forward to your reply.

Greetings,
Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ruth Goldberg
Top achievements
Rank 1
answered on 16 Mar 2010, 04:34 PM
I installed version Q1 2010 and the problem has been fixed.
0
jerry
Top achievements
Rank 1
answered on 25 May 2010, 05:15 PM
I am unable to get the latest version of the controls because of the schedule of my project but I still can't find a way around this.  I tried all the suggestions and it still sorts 1, 10, 2, 3, 4, 5, etc..

Here is how I create my column for my grid. 

GridViewDecimalColumn tsORDER = new GridViewDecimalColumn();       
 
tsORDER.UniqueName = "ORDER"
tsORDER.HeaderText = "Order"
tsORDER.FieldName = "ORDER"
tsORDER.ReadOnly = true
tsORDER.Width = 75; 
tsORDER.DataType = typeof(Int32); 
 
gvTable.Columns.Add(tabscrORDER); 
 
 

The value of this column is an int variable that keeps count in a loop. 

Any help would be appreciated.

Thank You
0
jerry
Top achievements
Rank 1
answered on 25 May 2010, 05:28 PM
I just corrected my issue. 

I was using a datatable to bind to my grid.  I went to my definition where I add columns to my datatable and I set ORDER to be typeof(int) and it fixed my sorting problem.

Thank you
0
Jack
Telerik team
answered on 27 May 2010, 04:34 PM
Hi jerry, I am glad to hear that you have resolved the issue. If you need further assistance, feel free to contact us.

Greetings, Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Nadine
Top achievements
Rank 1
Answers by
Jack
Telerik team
Nadine
Top achievements
Rank 1
Ruth Goldberg
Top achievements
Rank 1
jerry
Top achievements
Rank 1
Share this question
or