473,655 Members | 3,057 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 2386
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
1835
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 ListView (which is located on my other Tab). Now IF I click on the 2nd Tab... the Info IS to be sorted out - as I've set
6
4627
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(); listView1.Items.Add (myString); } Is there a way I can fill up the second column this easily? Thw way I'm currently doing it is using the subitems property to add it. Unfortunately,
0
1419
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 have a SqlServer CE table named students that has 2 fields: students name and grade.
2
2962
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, etc. The ListView is in Details, with headers and an Icon. What I am trying to accomplish is to rename/append check mark file massively (at once). This is accomplished by the user inputting a name into a provided
19
25450
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 sort columns based on the column header the user has clicked in both Ascending and Descending formats.
6
3399
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 listview, removing the item obviously keeps everything fine but the second I use insert the item is added to the *end* of the listview. Does anyone have any tips on how I can solve this issue?? Call Items.Remove(SourceItem)
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 answer but anyways here is my code any help would be greatly apperciated. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lvTest.Items.Add("1001") lvTest.Items.Add("5000")...
5
12299
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 TreeList". Has someone information about open source/freeware project/code? Thanks. (Ilqlo)
12
3399
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. Very simple. I would like to create listviewitem's for display in a listview control. The listview items need to contain properties from Internet Explorer windows i've managed to collect into an arraylist.
0
8296
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
8710
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
7310
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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
5627
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
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.