473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sorting a Datatable

Greetings,

I am trying to sort this values on a datatable

1
2
12rw
3
12r
4v
10a
e1
1w3

This was suposed to be sorted like this

1
1w3
2
3
4v
10a
12r
12rw
e1

I can't find a solution to sort this way.

Can anyone help me?
Jul 24 '07 #1
3 2505

You could parse each string to get the preceding numeric values until the
first character is found. Use the numeric values converted to a number to
sort. When the numbers match, use the characters that follow to make the
decision. Similarly, if the string starts with a character use that to sort.
You might want to write a method that does the comparison between two strings
the way you want and use that in a bubble sort function.

Adrian.
--
[Please mark my answer if it was helpful to you]


"Diogo Alves" wrote:
Greetings,

I am trying to sort this values on a datatable

1
2
12rw
3
12r
4v
10a
e1
1w3

This was suposed to be sorted like this

1
1w3
2
3
4v
10a
12r
12rw
e1

I can't find a solution to sort this way.

Can anyone help me?
Jul 24 '07 #2
Why would you use a bubble sort function for this, or any application,
for that matter? It takes O(N^2) time to do this, just way too long. There
are much faster sorting algorithms out there (quicksort, for example).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Adrian Voicu" <Ad*********@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...
>
You could parse each string to get the preceding numeric values until the
first character is found. Use the numeric values converted to a number to
sort. When the numbers match, use the characters that follow to make the
decision. Similarly, if the string starts with a character use that to
sort.
You might want to write a method that does the comparison between two
strings
the way you want and use that in a bubble sort function.

Adrian.
--
[Please mark my answer if it was helpful to you]


"Diogo Alves" wrote:
>Greetings,

I am trying to sort this values on a datatable

1
2
12rw
3
12r
4v
10a
e1
1w3

This was suposed to be sorted like this

1
1w3
2
3
4v
10a
12r
12rw
e1

I can't find a solution to sort this way.

Can anyone help me?

Jul 24 '07 #3

I don't know, it's the first thing that came to mind :) Obviously you can do
it in many other ways as long as you understand where to start.

Adrian.
--
[Please mark my answer if it was helpful to you]


"Nicholas Paldino [.NET/C# MVP]" wrote:
Why would you use a bubble sort function for this, or any application,
for that matter? It takes O(N^2) time to do this, just way too long. There
are much faster sorting algorithms out there (quicksort, for example).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Adrian Voicu" <Ad*********@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...

You could parse each string to get the preceding numeric values until the
first character is found. Use the numeric values converted to a number to
sort. When the numbers match, use the characters that follow to make the
decision. Similarly, if the string starts with a character use that to
sort.
You might want to write a method that does the comparison between two
strings
the way you want and use that in a bubble sort function.

Adrian.
--
[Please mark my answer if it was helpful to you]


"Diogo Alves" wrote:
Greetings,

I am trying to sort this values on a datatable

1
2
12rw
3
12r
4v
10a
e1
1w3

This was suposed to be sorted like this

1
1w3
2
3
4v
10a
12r
12rw
e1

I can't find a solution to sort this way.

Can anyone help me?


Jul 24 '07 #4

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

Similar topics

9
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...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
4
by: Richard | last post by:
When i try sorting in the database, it sorts the numbers: 0 1 102 2 304 305 4 etc....
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...
4
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...
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
3
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work....
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
1
by: castron | last post by:
Hello All, I have a grid view that allows sorting, paging, editing, etc. Under On Load event, if I check: if(!IsPostBack){ DisplayData(); }, the Edit portion works fine. However, the Sorting...
0
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,...
0
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...
0
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...
1
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.