By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

DataTable sorting, determining type of a column during the sort.

P: n/a
I've filled a DataTable with columns that have custom type (a class that I'm
using to keep track of other things, not just a value). When the .Select
method goes to sort this column, how do I let .Net know what value I want
used for the sort?

Sometimes it's going to be sorted as a decimal and other times a string. I
don't really know which until runtime.

Thank you.
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you specify select statement like this..

Table.Select("Col1 > 10","Col2 asc");

based on your Col2 datatype, its going to sort. if your Col2 is of string
type, it will do string comparision to sort. and same for int or any other
datatype.

hth,
Av.

"Clinton Pierce" <cp*****@payroll1.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
I've filled a DataTable with columns that have custom type (a class that
I'm
using to keep track of other things, not just a value). When the .Select
method goes to sort this column, how do I let .Net know what value I want
used for the sort?

Sometimes it's going to be sorted as a decimal and other times a string. I
don't really know which until runtime.

Thank you.

Nov 16 '05 #2

P: n/a
You missed the point.

The table doesn't contain strings, decimals, integers, or anything like
that. It contains my own objects. The columns were defined something like
this:

System.Type mot = new MyObject.GetType();
DataColumn dc = new DataColumn("somename", mot);

When I sort on "somename" it's arbitrarily calling MyObject's ToString()
method to get the value for sorting. This is wrong. I know it's being
stored as the object because I can pull it out again later and use it just
fine like this:

MyObject foo = ((MyObject)dataSet.Table[tablename].Rows[0]["somename"]);

For *sorting* purposes at runtime I can look at an individual Object of type
MyObject and get a sortable-representation of it (string, decimal, etc..).
And, by design, everything in a column of a table will wind up with a
similar sortable representation.

What I expected to happen was that for Objects in a table that
DataTable.Select() didn't know about, it would look for an ICompare
interface or something on an object. It doesn't appear to, it's just
calling ToString().
"avnrao" <av*@newsgroups.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
you specify select statement like this..

Table.Select("Col1 > 10","Col2 asc");

based on your Col2 datatype, its going to sort. if your Col2 is of string
type, it will do string comparision to sort. and same for int or any other
datatype.

hth,
Av.

"Clinton Pierce" <cp*****@payroll1.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
I've filled a DataTable with columns that have custom type (a class that
I'm
using to keep track of other things, not just a value). When the ..Select method goes to sort this column, how do I let .Net know what value I want used for the sort?

Sometimes it's going to be sorted as a decimal and other times a string. I don't really know which until runtime.

Thank you.


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.