Link to home
Start Free TrialLog in
Avatar of wilko100
wilko100

asked on

How do i sort a date column out on on a ListView object using VB6?

I have a listview in VB6 with a column for dates but ever when i click pn the column header is kinda of sorts but groups the date for example:
01/jan/2008
01/Nov/2007
01/Feb/2008
02/March/2008
02/Nov/2007 etc etc
the propertys for the LV are limited (or im blind and cant see an option in the propertys) and i thought maybe adding another column for dates in YYYY/MMDD, hinding it and linking it to the original date column header so that when the user clicks on the column header it sorts the YYY/MM/DD column, that a good idea or can you suggest a better way?
Avatar of rettiseert
rettiseert

I always use the "adding a hidden (zero widht) column ready to sort", works great for me even when are hundreds of rows and requires very little code.
hi

your way would work fine, or you could also try the code provided in this link.
http://support.microsoft.com/kb/170884
Avatar of wilko100

ASKER

How easy is it to code so that i click on the column header and it sorts the hidden column?
something like?
Column_Click
 .sort = "hidden cloumn

Private Sub LV_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
If ColumnHeader.Position = 2 Then       'actual date column
    LV.SortKey = 0                      'hidden date column
    LV.SortOrder = lvwAscending
    LV.Sorted = True
End If
End Sub

Open in new window

Ah ok i understand that (nearly there myself honestly)...thats fantastic but where does it get the date format from? for example, it sorts 'actual column' (in this case dates) taken from hidden column but there is nothing to sort in hidden column. do i state the above and hidden column coverts it to string then the code above sorts it? Hope its not a daft question but im new to coding
You would have to add the values to the hidden column manually. Set its value to the date column you need to sort in the format yyyymmdd so that it will be sorted correctly.
ok, so enter the dates into the hidden column manullay, then set that format for the hidden to YYYYMMDD then sort?
yes, you can create a hidden column for each date columns you need to sort.
Ok i understand as far as adding a hidden column and that will be used for sorting the visible date column, so that when i click on the date coulmn it triggers the sort in hidden coumn. It just seems a little extreme to manually have to add string dates in the hidden column, especially when i have around 2000 dates! Any other way still using this approach? If that is the only way using this approach i suppose i could use a SQL script to enter stuff in, but what would the code be for sorting the hidden column (thats in text format, MMDDYYY) i have the code for the event so thats sorted, thanks
Anyone out there can help me find the solution!! Cheers
ASKER CERTIFIED SOLUTION
Avatar of ee_rlee
ee_rlee
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cool i just tried some stuff and works a treat, thanks for the reply