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

Sorting Number Type

48
Hello,

I am currently using Listview control.
The sorting feature of the control is useful.
Expand|Select|Wrap|Line Numbers
  1. <ListviewCtrlName>.Sorted = True
  2. <ListviewCtrlName>.SortKey = <FieldToSort>
  3. <ListviewCtrlName>.SortOrder = <SortOrder>
It sorts well with Text type but is weird when sorting Number Type.
Ex.
(before sorting)
[1st] 3
[2nd] 2
[3rd] 11
[4th] 4
[5th] 1

(after sorting)
[1st] 1
[2nd] 11
[3rd] 2
[4th] 3
[5th] 4

The correct one should be:
[1st] 1
[2nd] 2
[3rd] 3
[4th] 4
[5th] 11

How to sort number type correctly?
Apr 28 '09 #1
13 4313
ADezii
8,834 Expert 8TB
@keirnus
If you set the SortKey Property = 0 it will Sort using the ListItem Object's Text property. Try setting it to a Value between 1 and Number of ColumnHeaders - 1 to Sort using the SubItem whose Collection Index you specify, then see what happens.
Apr 28 '09 #2
keirnus
48
@ADezii
(I edited this reply coz I was wrong...sorry)

Thanks for the reply ADezii.

But I noticed something. The SortKey is the column index in listview.
It starts with zero(0) so in my example, since there's only 1 column so
it starts with index 0. If I got 3 columns and want to sort the 2nd, I will
be using index 1. (please correct me if I'm wrong)

I tried sorting the column with number type and yet the sorting is wrong.
The sort is treating it like an alpha when it should be numeric.
Apr 28 '09 #3
ADezii
8,834 Expert 8TB
@keirnus
As soon as I get a chance, I'll create a DB with a ListView incorporated in a Form and see if I can 'Sort' the problem (LOL)!
Apr 28 '09 #4
NeoPa
32,556 Expert Mod 16PB
It looks like you're simply sorting on the string value, instead of the numeric value.
Apr 28 '09 #5
NeoPa
32,556 Expert Mod 16PB
@keirnus
Which values are you actually using?
Apr 28 '09 #6
ADezii
8,834 Expert 8TB
@keirnus
Keirnus, I do see your dilemma in that the ListView Control seems to always want to do an Alpha Sort on Column Headers regardless of the Data Type. I'll look into it further at a later Date, but I do have a solution at this time.
  1. In the ColumnClick() Event of the ListView Control, if the Index of the ColumnHeader is anything but the 1st Column, set the SortKey = ColumnHeader.Index -1 then set the Sorted Property of the ListView = True.
  2. If the Index of the ColumnHeader = Column 1, then:
    1. Clear the ListView Control
    2. Set the Sorted Property = False
    3. Create a RecordSet setting the Primary Sort Order of your Numeric Field to Ascending
    4. Re-populate the ListView based on this Recordset
    5. This entire process will be transparent to the User, and, unless you are dealing with very large Recordsets, will populate quite rapidly.
  3. I created a Demo Database for you, simply download the Attachment, then Click on the Column Headers to set the Sorts for the 3 Columns
Apr 28 '09 #7
NeoPa
32,556 Expert Mod 16PB
@keirnus
I'm confused.

I started by assuming you were referring to a ListBox control, but I didn't find any of these properties there so I stopped and looked again.

I found the ListView control, but even there, I found those properties missing.

I'm using Access 2003. Is it possible you're using a different version?
Apr 29 '09 #8
ADezii
8,834 Expert 8TB
@NeoPa
Hello NeoPa, these Properties definately exist for the ListView Control but not via the Normal Interface, you can access them either by:
  1. Right Click the ListView Control ==> ListViewCtrl Object ==> Properties ==> Sorting Tab
  2. Object Browser ==> Class = MSComctlLib ==> Search for ListView ==> Properties, Methods, and Events will appear in the Right Hand Pane
Apr 29 '09 #9
missinglinq
3,532 Expert 2GB
I can't lay my hands on a reference right now, but I'm about 99.9% sure that ListView controls only sort on strings and treat any other datatype as if they were strings when sorting, which is what it's doing here.

Linq ;0)>
Apr 29 '09 #10
ADezii
8,834 Expert 8TB
@missinglinq
I think you hit the nail on the Head, any attempt to Sort on Native Numeric Types, or Data Types coerced to Numeric, seem to fail. It appears as though the ListView must be repopulated as indicated in my prior Post.
Apr 29 '09 #11
NeoPa
32,556 Expert Mod 16PB
@ADezii
Bizarre. It's almost as if I'm looking at a different, unrelated, ListView control.

Method 1 would be default for me. Didn't find anything (not even a sorting tab).
I also tried IntelliSense, but that yielded nothing either.

I'd like to see if I could find a way of coercing the item to a numeric value, but it's hard if I can't even find it.

Never mind.
Apr 29 '09 #12
ADezii
8,834 Expert 8TB
@NeoPa
  1. Are we talking about the same animal, namely:
    Expand|Select|Wrap|Line Numbers
    1. Form Design View ==> Insert ==> ActiveX Control ==> Microsoft ListView Control, version X.X
  2. Did you download the Attachment in Post #7 of this Thread, and is it functional?
Apr 29 '09 #13
NeoPa
32,556 Expert Mod 16PB
  1. I used the Toolbox button and More tools. If this is the same I don't know.
  2. No. I rarely download attachments. I don't often have the time to get into questions that deeply, and I never download anything at my work PC.
PS. It's not important if I don't know too much about this control. I was only interested to see if I could help with the question. As you guys seem to be covering it anyway, it's hardly a problem if I'm on a rail track that is sort of parallel, but verges off on its way to a different city.
Apr 29 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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)) ...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
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....
25
by: Dan Stromberg | last post by:
Hi folks. Python appears to have a good sort method, but when sorting array elements that are very large, and hence have very expensive compares, is there some sort of already-available sort...
9
by: Dylan Parry | last post by:
Hi folks, I have a database that contains records with IDs like "H1, H2, H3, ..., Hn" and these refer to local government policy numbers. For example, H1 might be "Housing Policy 1" and so on....
1
by: DJP | last post by:
Hello all, I am having problems sorting my xml on two fields. For each result I want to sort resultItem elements based on child elements typId and macroSequence. so I want result element like...
7
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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.