Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sort Listview on Column Click

Posted on 2006-06-10
2
Medium Priority
?
1,114 Views
Last Modified: 2013-12-25
I have a listview I want to sort via column click. Problem is, I want it based on content. I am using this right now:

    With lvResults
        .SortKey = ColumnHeader.Index - 1
        .SortOrder = IIf(.SortOrder = lvwAscending, lvwDescending, lvwAscending)
        .Sorted = True
    End With

Which works fine for text, but horribly for numbers.

How do I modify this so that it will sort numbers as numbers instead of a string?
0
Comment
Question by:DrDamnit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Sethi earned 2000 total points
ID: 16876721
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 16876730
Needs:
1 Form
1 Listview, named "lvResults" (CTRL-T / Microsoft Windows Common Controls 6.0)

======================================
Please run the program. Then click on the 1st ColumnHeader
======================================



Private Sub Form_Load()
Move 0, 0, Screen.Width, Screen.Height
 lvResults.Move 0, 0, Width, Height * 0.85
    Me.Caption = "ListView"
     lvResults.GridLines = True
     lvResults.FullRowSelect = True
   
     lvResults.View = lvwReport 'lvwReport is needed to show the list items one below the other
 
     lvResults.ColumnHeaders.Clear
     lvResults.ColumnHeaders.Add , , "Index"
     lvResults.ColumnHeaders.Add , , "Description1"
     lvResults.ColumnHeaders.Add , , "Description2"
     lvResults.ColumnHeaders.Item(1).Width = 600
     lvResults.ColumnHeaders.Item(2).Width = 9900
     lvResults.ColumnHeaders.Item(3).Width = 4500
    Dim o As ListItem
   

Dim y&
    For y = 0 To 19
        Set o = lvResults.ListItems.Add(y + 1, , CStr(r))
         lvResults.ListItems(y + 1).Text = Format(y + 1, "0#")
    Next

End Sub




Private Sub lvResults_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

    lvResults.SortKey = ColumnHeader.Index - 1
    If lvResults.Sorted = 0 Then lvResults.Sorted = True: Exit Sub
    lvResults.SortOrder = IIf(lvResults.SortOrder, 0, 1)

End Sub

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question