DataGrid-DataView-XML-Sorting strings as numerics

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.
 
M

Miha Markic

You DataTable source should have the number datatype property instead of
string one I guess.
 
J

Joe Rattz

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.
 
M

Miha Markic

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top