473,670 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting Number Type

48 New Member
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 4368
ADezii
8,834 Recognized Expert Expert
@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 New Member
@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 Recognized Expert Expert
@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,569 Recognized Expert Moderator MVP
It looks like you're simply sorting on the string value, instead of the numeric value.
Apr 28 '09 #5
NeoPa
32,569 Recognized Expert Moderator MVP
@keirnus
Which values are you actually using?
Apr 28 '09 #6
ADezii
8,834 Recognized Expert Expert
@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.In dex -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,569 Recognized Expert Moderator MVP
@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 Recognized Expert Expert
@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 Recognized Expert Specialist
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

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

Similar topics

7
3255
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)
22
4137
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) { return -1; } else
8
3509
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 the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
4
1700
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
2212
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 function that will merge like elements into a chain, so that they won't have to be recompared as many times? Thanks!
9
2603
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. For some more insight, not all policies will be prefixed with an "H", an in fact they could be prefixed with *any* letter combination, but they will always end with a number. When I retrieve them from the database I use "ORDER BY id" to get them...
1
1178
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 <result> <resultItem> <typId>82</typId> <macrosequence>1/<marcosequence> </resultItem>
7
4811
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...
5
4933
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 there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8466
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
8384
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
8813
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...
0
8659
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...
1
6212
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4208
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...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1791
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.