Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort ListView by number or Date

Status
Not open for further replies.

agfon

Programmer
Mar 25, 2005
38
0
0
US
I currently have a listview with multiple columns of data. This includes text, date, and value columns.

The sort option on the ListView sorts the selected column Alpha-Numerically. Therefore, dates and values are sorted wrong.

I've searched Tek-Tips and the web to find a solution to this. Most solutions are directed toward visual basic applications instead of VBA.

Does anyone have a solution to this?

Thanks.

-agfon
 

Hi,

Would you please post a sample of the data that is sorting correctly & incorretly?

Skip,
[sub]
[glasses] [red]Be Advised![/red] Dyslexic poets...
write inverse! [tongue][/sub]
 
Skip,

Here's the code. It sorts text columns without any problem. Columns with values (e.g. 1, 6, 50, 300) are sorted 1, 300, 50, 6.

[blue]Function ListView_ColumnClick(frmName As String, frmLV As String, ColumnHeader As Object)
With Forms(frmName).Controls(frmLV)
.SortKey = ColumnHeader.Index - 1
If .SortOrder = lvwAscending Then
.SortOrder = lvwDescending
Else
.SortOrder = lvwAscending
End If
.Sorted = True
End With
End Function[/blue]

-agfon
 


I asked for [red]data[/red]!

Skip,
[sub]
[glasses] [red]Be Advised![/red] Dyslexic poets...
write inverse! [tongue][/sub]
 
Skip,

Data sorted by column 1
Column 1: AZ, CA, DE, IL, MS
Column 2: 300, 50, 1, 8, 77

Data sorted by column 2
Column 1: DE, AZ, CA, MS, IL
Column 2: 1, 300, 50, 77, 8

-agfon
 


Thanks for posting you data in such an easy to use format.

Your column 2 data is TEXT and not numeric. Hence the sorting sequence 1,3,5,7,8 (first CHARACTER of the STRING)

Solution: Change TEXT to NUMERIC

Skip,
[sub]
[glasses] [red]Be Advised![/red] Dyslexic poets...
write inverse! [tongue][/sub]
 
What value do I change from text to numeric? The field in the table is already numeric. Is there something on the Listview itself that can be changed?

-agfon
 


Then REENTER you "numbers"
[tt]
Column 2: 300, 050, 001, 008, 077
[/tt]


Skip,
[sub]
[glasses] [red]Be Advised![/red] Dyslexic poets...
write inverse! [tongue][/sub]
 
Thanks, Skip. I've seen this solution. I'm trying to avoid having a series of leading zeros.

-agfon
 
Use leading spaces with the Format function when you populate the ListView.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top