473,624 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7177
you specify select statement like this..

Table.Select("C ol1 > 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*****@payrol l1.com> wrote in message
news:e$******** ******@TK2MSFTN GP10.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.GetTyp e();
DataColumn dc = new DataColumn("som ename", 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)data Set.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.Selec t() 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******** ********@TK2MSF TNGP12.phx.gbl. ..
you specify select statement like this..

Table.Select("C ol1 > 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*****@payrol l1.com> wrote in message
news:e$******** ******@TK2MSFTN GP10.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
3676
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 - Data sorting (preferrably intelligently determining data type based on content) - If possible, locking the first column from scrolling
3
6051
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. I also apply some styling to this datagrid so I only see some columns from this table
0
1834
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 assign the datatable.dataview to my datagrid.datasource member so it will display my results.. I need to give the user an option to change the order of this data, I have a
1
1977
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 process, behind the scenes, I combine the 2 datagridas into a datatable, sort and do processing for creating a load into another system. My problem is that when I combine the two datagrids into the 1 datatable, I can only sort in a dataview. When...
3
1873
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 instance, if you try to run this code: DataTable userTable = new DataTable(); userTable.Columns.Add("userID", Type.GetType("System.Int32"));
6
3341
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 good for viewing it sorted, but I need it to actually _be_ sorted, and testing seems to show that the view doesn't do the trick. If I iterate through the rows in my code and look at the sorted column in each step, it's not sorted. Now, I can...
7
4811
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 expandable row, the hidden row is made visible with css. The problem is when i sort the rows, the hidden rows get sorted as well which i don't want and want to be moved (while sorting) relative to their parent rows. The following is my complete html code...
7
19996
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. When it is done sorting I want the splash screen dissapear. What I had been doing was using the CellClick and Sorted events: private void myDGV_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) {//sorting
5
4931
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 there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8672
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1474
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.