DataGrid-DataView-XML-Sorting strings as numerics

  • Thread starter Thread starter Joe Rattz
  • Start date Start date
J

Joe Rattz

I am populating a DataGrid with xml. I need to be able to
sort some of the columns. However, the DataView.Sort is
treating my strings (which are numbers in string form from
the xml) as strings and not formatting them as numbers.
So, I get:

1,11,2,22

instead of:

1,2,11,22

How do I get the DataView.Sort to treat these strings as a
numeric type?

Thanks.
 
You DataTable source should have the number datatype property instead of
string one I guess.
 
You are not being very specific so I am not sure what you
mean exactly. I have tried changing the datatype of the
column I want treated as a numeric, but I get an error
telling me that I cannot change the datatype once there is
data in the column, and also bear in mind that the column
doesn't exist until the databind, when the data is placed
in the column.
 
Hi Joe,

You can't change the column's datatype after it contains rows, yes.
I think you should include dataset schema within your xml so the dataset
will know the datatypes of each column.
You might check the
DataSet.ReadXml Method
help topic (it shows you how to write and read schema - you might examine
the written xml on how the schema is specified)
 
Back
Top