0

I have datatable and it has two columns named "RegNo", "Name"
RegNo is a string field.
This is an example

"RegNo"     "Name"
======      =====
    55      name1
    10      name2
    5555    name3
    75      name4
    10A     name5

i used this code for sort

datatable.DefaultView.Sort = "RegNo ASC"

But after sort the RegNo column shows like this.

10
10A
55
5555
75

I want it like this

10
10A
55
75
5555

How to do it.....???

Edited by weeraa: tab issue

3
Contributors
4
Replies
21
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
0

That's a common sorting problem with numerical data represented as strings. Correct the problem by right-aligning the numbers, embed either spaces or 0s to the beginning of each number so that all numbers are the same width. for example the first value, 10, would become 0010 so that it's the same width as 5555.

0

Thanks Ancient Dragon and ryanjayson for the reply. It is not be able to do so, (10 change to 0010) because this is real world application. Customers already have this reg nos. I gave an example. Reg no has various patterns. (Eg: 10, 10A, 10-B etc...) Is there no any other way????? :(

0

Read the data into an array instead of directly into a grid or something else, move the suffix's (A, B, etc) into another column so that the first column is only numeric, sort the array treating the first column as numeric instead of string, then move all data to it's final destination. This also means there is no point in having the datatable sort the data.

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.