Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I sort a dataview on a column that contains integers?

Newbie
 
Join Date: Oct 2009
Posts: 4
#1: Oct 15 '09
Hello, using c# I'm trying to sort a dataview on a column that contains integers. Apparently the option dvTempt.Sort = sFieldName; only sort as strings(or ASCII)...ex
5, 10, 11, 12, 101, 22, 24 is sorting 10, 101, 12, 22, 24, 5 when it should be sorting 5, 10, 11, 22, 24, 101. Could somebody help me with this?.

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Oct 15 '09

re: How do I sort a dataview on a column that contains integers?


If the underlying datatype is an integer, it should have sorted them as integers.
I think there is a way to specify a specical custom sort function right?
Newbie
 
Join Date: Oct 2009
Posts: 4
#3: Oct 15 '09

re: How do I sort a dataview on a column that contains integers?


here is the code I'm using:

string sFieldName = "iWord";
dvTempt.Sort = sFieldName;

whrere iWord is a column in the dataview and contains numbers(int). But it is not sorting properly, it looks like it is considering the content of the column as ASCII or strings. The order in the column before the sort is as follow:
18, 22, 10, 24, 101, 5...after the sort: 10, 101, 18, 22, 24, 5...when it should be
5, 10, 18, 22, 24, 101
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Oct 19 '09

re: How do I sort a dataview on a column that contains integers?


Right, but what is the datatype of column "iWord"? is it a string or an Int or?
Newbie
 
Join Date: Oct 2009
Posts: 4
#5: Oct 19 '09

re: How do I sort a dataview on a column that contains integers?


Hello Plater, the datatype of the column "iWord" is an integer but the sort is sorting like if was a string and it is not sorting properly. This column is in a dataset and I'm using it in a dataview to do the sort.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#6: Oct 19 '09

re: How do I sort a dataview on a column that contains integers?


So dvTempt.Columns["iWord"].ValueType reports "int" ?
Reply