473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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

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
2 7162
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Matt Kruse | last post by:
I'm looking for the best JS/CSS solution to add functionality to tables. The only browser which needs to be supported is IE5.5+, but no activeX can be used. to be able to do: - Fixed header row...
3
by: tomi | last post by:
Hi I have following problem. I have a datatable filled with some data. Each row holds its ID (column named "Row_ID") DataTable dtTable; I have a datagrid to which I assign this datatable....
0
by: Nathan Franklin | last post by:
Hello Guys, I have been trying to work this our for so long, but I just can't seem to find the answer. I am loading a datatable from a an access database using an oledbdataadapter. I then...
1
by: Lyners | last post by:
I am trying to figure out the best way to do this (currently I am having a problem sorting). I have a vb.net program that contains 2 datagrids on a form for the end user. When the user is ready to...
3
by: WB | last post by:
Hi, I have a DataTable, which I'd like to sort before using it for other operation. However, I notice that even after I call the .DefaultView.Sort = "username", the view is still not sorted. For...
6
by: David P. Donahue | last post by:
I've been looking around for ways to sort the rows in a DataTable, and everything seems to point to just changing the Sort property on that DataTable's DefaultView property. That's all well and...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
7
Plater
by: Plater | last post by:
I am having trouble determining when my DataGridView object is sorting (based on a column header click). The idea is, in a large table, sorting the columns takes time, so I show a splash screen....
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.