473,224 Members | 1,953 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,224 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 2735
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.