473,757 Members | 10,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting problem

Hi All,

I need to loop through a sorted datatable. Looping is not a problem, but
sorting is.

The datacolumns on which I want to sort, exists of numbers, which causes the
10 to appear before the 2.

This is the code I use to sort the table

DataRow[] drarray = myTable.Select( "", "VerticalPositi on asc,
HorizontalPosit ion asc", DataViewRowStat e.CurrentRows);

Anyone an idea how I can sort the table correctly?

Thanks in Advance,

Michel
Nov 16 '05 #1
6 1724
Use the Table's DefaultView and sort on it.
http://www.knowdotnet.com/articles/dataviewsort.html

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Michel" <Mi****@discuss ions.microsoft. com> wrote in message
news:E8******** *************** ***********@mic rosoft.com...
Hi All,

I need to loop through a sorted datatable. Looping is not a problem, but
sorting is.

The datacolumns on which I want to sort, exists of numbers, which causes the 10 to appear before the 2.

This is the code I use to sort the table

DataRow[] drarray = myTable.Select( "", "VerticalPositi on asc,
HorizontalPosit ion asc", DataViewRowStat e.CurrentRows);

Anyone an idea how I can sort the table correctly?

Thanks in Advance,

Michel

Nov 16 '05 #2
Michel,

You mean something as this?
\\\
DataView dv = new DataView(dt);
dv.Sort = "bla"; // sorts column bla
DataTable dtnew = dt.Clone();
foreach (DataRowView dvr in dv)
dtnew.ImportRow (dvr.Row);
dt.Clear();
dt = dtnew.Copy();
///

Cor
Nov 16 '05 #3
hmmm...seems you are using string sorting (which puts '10' before '2'),
whereas it sounds like you'd like to sort as if these were integer
values.

If the values in this column are always integers, why not have that
column in the set hold integers? That might work.

If not, you may have to do your own sorting, casting all of them to
integers, and doing...oh I don't know...a bubble sort on the whole data
set based on the value of the column once it's cast to int?
HTH,
F.O.R.

Nov 16 '05 #4
Hi,

Indeed, I'm sorting a string column. If filled in, the values shall alway's
be int's. But they can be blank. (Dataset is generated from an xml file, and
not alway's a value is provided).

Maybe adding an int column and sorting on that column may do the trick.
Gonna try it out.

Kind regards,

Michel

"Olorin" wrote:
hmmm...seems you are using string sorting (which puts '10' before '2'),
whereas it sounds like you'd like to sort as if these were integer
values.

If the values in this column are always integers, why not have that
column in the set hold integers? That might work.

If not, you may have to do your own sorting, casting all of them to
integers, and doing...oh I don't know...a bubble sort on the whole data
set based on the value of the column once it's cast to int?
HTH,
F.O.R.

Nov 16 '05 #5
If you have the ability to change the XML schema, just change the
attribute or element type for the "column" to be an integer. If the
value is not supplied then ADO.NET will set the column value for that
row to be System.DBNull, and sorting should work correctly.

After all, if the data is not supplied, then it's "null", not blank,
right? Blank means that the tag was there in the XML but its value was
an empty string. If this is your case (if the XML sometimes contains
the tag or attribute but with an empty-string value) or if you have no
control over the schema, then you'll have to use one of the other
workarounds mentioned here.

Nov 16 '05 #6
Have the Database put the data into a workable format for you. Instead of :

Select VerticalPositio n, HorizontalPosit ion, x, y, z
from mytable
where ....

make it:

Select VerticalPositio n, HorizontalPosit ion, x, y, z,
ISNULL(CAST(Ver ticalPosition as Int), -1) as sortVerticalPos ition,
ISNULL(CAST(Hor izontalPosition as Int), -1) as sortHorizontalP osition,
from ....

then use:
DataRow[] drarray = myTable.Select( "", "sortVerticalPo sition asc,
sortHorizontalP osition asc",
DataViewRowStat e.CurrentRows);

Replace the "-1"s in that to something that is reasonable to a NULL
value --- presumably some very high or very low value.

"Michel" <Mi****@discuss ions.microsoft. com> wrote in message
news:E8******** *************** ***********@mic rosoft.com...
Hi All,

I need to loop through a sorted datatable. Looping is not a problem, but
sorting is.

The datacolumns on which I want to sort, exists of numbers, which causes the 10 to appear before the 2.

This is the code I use to sort the table

DataRow[] drarray = myTable.Select( "", "VerticalPositi on asc,
HorizontalPosit ion asc", DataViewRowStat e.CurrentRows);

Anyone an idea how I can sort the table correctly?

Thanks in Advance,

Michel

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2533
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys() sorted_feature_vector.sort() #feature_vector.keys()=sorted_feature_vector
9
2587
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the DataView. (I'm writing in C# with the v1.1.4322 of the .NET Framework, in Window2K server"). First of all, here are the two methods I have used in order to apply the sorting property to the DataView 1. Simply defining the sort order and colum DataView...
7
3266
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) CType(local4, Short) = CType(src, Short)
4
2545
by: John Bullock | last post by:
Hello, I am at wit's end with an array sorting problem. I have a simple table-sorting function which must, at times, sort on columns that include entries with nothing but a space (@nbsp;). I want all of the spaces to be put in the first slots of the array. IE 6 does this. But Firefox 0.9.1 doesn't, and I don't know why. I have not been able to reproduce it in very simple form (which is itself a puzzle). But example code is...
4
4284
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event is stored in a double linked list, the whole list is sorted for the next round. My problem appears when subjecting the program to heavy load, that is, when I run the simulation for more than 10,000 miliseconds (every event occurs in...
4
3099
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in grid. And with rebinding, sorting image (little triangle on the column header) goes away. I need to show sorting image as well custom sorting. Please help. Thanks
7
4827
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...
1
2180
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns (LoginName,UserName) 2. the datagridview sorting is set to automatic, so when i click on the column header is sorts well. 3. i put in an event handler for the CellEndEdit Event, so whenever the user of the program changes the content of a cell in the LoginName...
1
7189
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar methods or syntax to a less experienced perl coder. I will post links to online resources you can read if necessary. Experienced perl coders might find nothing new or useful contained in this article. Short Review In part one I showed you some...
7
20038
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
0
9489
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
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
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
9885
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
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
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
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
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
3
2698
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.