473,398 Members | 2,343 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,398 software developers and data experts.

Sorting a Datagrid containing Dash / Hyphen

Hi,

I'm trying to sort a DataGrid (dotNet Windows Forms).
Trouble is, the column I'm trying to sort on contains part numbers of the
form
xxx-yyy where

xxx - Part Type
yyy - Part Size.

The DataGrid sorts into a sequence somthing like:

10-199
10-299
103-10
103-20
10-399

wheras I would like:
10-199
10-299
10-399
103-10
103-20

It seems that it ignores the '-' when sorting (trying to be helpful??).
Anyone got any ideas how I can get the DataGrid to sort using exactly what
is in the column rather than applying any other 'rules' to it.

If I replace the '-' s with '~'s then it sorts fine, but that is not really
a solution.

Look forward to hearing any suggestions.

(I haven't included any details on the code or the data source as they don't
seem to make any difference, but if anyone things it is relevent, I'm happy
to supply them.)

Thanks,

Chris.

PS Apologies if the post appears more than once, but I originally tried to
post it via dotNET247 and after 3 hours it still isn't here...
Jul 21 '05 #1
4 2751
Chris,

It sorts just as Strings. And the hyphen is the decimal value 45 the zero 48
and that until the 9 which is decimal value 57. The tilde has the decimal
value 126. So there is nothing strange.

http://msdn.microsoft.com/library/de...es_chart_1.asp

What you think as a number is a string of characters that is sorted.
When you set the sort of the datagrid to disable, than you can think about
using an extra datacolumn with an expression, a dataview and datagridstyles.
Otherwise there are probably not much possibilities.

I hope this gives some idea's

Cor
Jul 21 '05 #2
> It sorts just as Strings. And the hyphen is the decimal value 45 the zero
48
and that until the 9 which is decimal value 57. The tilde has the decimal
value 126. So there is nothing strange.


I'm not sure that's true...

Like I said, the sort order is:
10-199
10-299
103-10
103-20
10-399

If it was doing a simple ASCII sort, '10-...' should come before '103...'
so the sequence is surely not plain ascii sorted. However if you ignore the
'-'s, the order is

10199
10299
10310
10320
10399

Which makes sense. This is why I think it is ignoring the '-' when doing the
sort.
I figure if you were sorting normal text, you would probably want (say)
'cooperation' to be sorted next to 'co-operation' so this behaviour would
be correct, however in this situation is is not. Maybe there is a flag to
chose the sort behaviour??

Regards,

Chris.

Jul 21 '05 #3
Chris,

I think you are completly right in all what you wrote, in my idea should
this be called a worse Bug

I made something to test the behaviour.

\\\
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Chris",Type.GetType("System.String "));
string[] str = new string[]
{"10-199","10-299","10-399","103-10","103-20"};
for (int i = 0;i < str.Length;i++){
dt.Rows.Add(dt.NewRow());
dt.Rows[i][0] = str[i];}
dt.DefaultView.Sort = "Chris ASC";
listBox1.DataSource = dt.DefaultView;
listBox1.DisplayMember = "Chris";
///

A solution, I cannot find something either.

Sorry, maybe somebody else has the solution.

Cor

Jul 21 '05 #4
> A solution, I cannot find something either.

Well thanks a lot for trying anyway...

Cheers,

Chris.
....ANYONE ELSE???
Jul 21 '05 #5

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

Similar topics

5
by: Phil Powell | last post by:
I have a client database in my db dev server environment I need to create, but the client name contains a dash "-". This blows up upon attempting to do create database my-site; How then do I...
0
by: Chris Mayers via .NET 247 | last post by:
Hi, I have a dotNET Windows Forms DataGrid that contains a column'Part Number' Problem is when I sort the grid on this column (eitherprogramatically or by clicking on the column header),...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
4
by: Chris Mayers | last post by:
Hi, I'm trying to sort a DataGrid (dotNet Windows Forms). Trouble is, the column I'm trying to sort on contains part numbers of the form xxx-yyy where xxx - Part Type yyy - Part Size.
8
by: simchajoy2000 | last post by:
I thought the only thing I had to do to disable column sorting in VB.NET was to set datagrid.AllowSorting = False. Unfortunately this has never worked for me. I discovered another set of code...
1
by: mats.broberg | last post by:
Dear all, I'm having a scientific text translated into the majority of western and eastern European languages* and have provided a small leaflet with typesetting rules for the translators. Some...
4
by: deancarstens | last post by:
Hi, This is a tougher one, but I'm quite sure someone will have a solution for this. Of course, a last minute thing thrown at me by my boss. I have a unique identifier consisting of regions,...
0
by: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= | last post by:
"C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 149, in Here it complains that it deals with the character U+2013, which is "EN DASH"; it complains that the encoding called "latin-1"...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...
0
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
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...

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.