473,503 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listview - Simple code but sorts in different format

103 New Member
The following code is for sorting,but that works in a different format:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub ListView1_ColumnClick(ByVal ColumnHeader As   MSComctlLib.ColumnHeader)
  2.  With ListView1  '// change to the name of the list view
  3.  Static iLast As Integer, iCur As Integer
  4.      .Sorted = True
  5.       iCur = ColumnHeader.Index - 1
  6.       If iCur = iLast Then .SortOrder = IIf(.SortOrder = 1, 0, 1)
  7.      .SortKey = iCur
  8.       iLast = iCur
  9.      End With
  10.    End Sub
This works as in alist view as:
num
1
12
2
23
2111
3
356

What wrong with the code???
THanks in advance:
Dec 22 '07 #1
6 2372
debasisdas
8,127 Recognized Expert Expert
What is wrong with the output? It is showing as per code. Sorting is done as per ascending sort considering as character not numbers.
Dec 22 '07 #2
Vbbeginner07
103 New Member
What is wrong with the output? It is showing as per code. Sorting is done as per ascending sort considering as character not numbers.
But I have to sort like
1
2
3
11
21
32
356
as if in the correct order, but the output is the one which is in #1, please go through.
Dec 22 '07 #3
debasisdas
8,127 Recognized Expert Expert
it is sorting considering the items as character strings not numbers
Dec 22 '07 #4
Vbbeginner07
103 New Member
it is sorting considering the items as character strings not numbers
Please help me to sort a list view including characters and numbers
Thanks in advance
Dec 27 '07 #5
debasisdas
8,127 Recognized Expert Expert
If a list view is sorted including characters and numbers ,that will be sorted as per character only. So it will consider numbers as characters also.
Dec 27 '07 #6
Killer42
8,435 Recognized Expert Expert
The basic problem here is that the sort functionality of the Listview control is treating the values as strings. If you consider the values to be strings, "2" is certainly a higher value than "15", simply because the "2" (ASCII code 50) is higher than the "1" (ASCII code 49). I imagine things might be more complex if dealing with Unicode.

This confusion between numbers and strings has been around for many years, and there are various ways in which one might work around it. These include (but are not limited to):
  • If possible, use your own code to do the sort, converting all values either to numbers, or two strings of the same length (such as "00015" and "00002"). I don't know whether the Listview control provides any way to customise the sorting, or not.
  • If the Listview control supports it, store the values in it as numbers rather than strings.
  • Add a hidden column and sort on that. In other words, if supported, add another column which is not possible to the user, and copy the values from the problematic column in a "sortable" format. For example, with leading zeroes as described in the first bullet point.
  • Sort the data before placing it in the listview. If it's coming form a database, this might mean including an ORDER BY clause in your SQL. If not, you might need to sort an array first, or simply change the order in which you add them to the ListView.
.
Dec 28 '07 #7

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

Similar topics

4
1818
by: Mr. B | last post by:
VB.net issue here. I've a strange event that I can't seem to figure out... On my Form, I've a TabControl (two Tabs)... On my first tab, I load an Ascii file and dump some info onto my...
6
4615
by: VM | last post by:
How can I fill up a listview with text file contents? My listview has two columns and the first column fills up with a while loop: while (myString != null) { myString = sr.Readline();...
0
1411
by: Sérgio Almeida | last post by:
Greetings I have a problem using listview control. Well, I belive that this is not realy a problem, but it's consuming me precious time. Here is the scenario (an example of my problem). I...
2
2955
by: MikeY | last post by:
Hi all, I am coding window forms in C#. My problem is this: I have created a "Check ListView" or a 'ListView' with checkbox's. I have populated the it with my files from my folders, mps, txt,...
19
25424
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
6
3385
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the...
3
472
by: Curtis | last post by:
I am trying to do a simple sort on a list view.With the listview control the first time I sort on the control it sorts the items but anytime after that it fails to sort. I'm sure this is a simple...
5
12287
by: IlQlo | last post by:
Hi! I'm working with Vb.Net 2005 to do an application that need a simple listview with sorting function but also with a tree layout to show the informations. A commercial examples is "Glacial...
12
3377
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
0
7280
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
7330
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
5578
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
5014
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
4672
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
3167
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
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
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.