Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to get a listview control to SORT DATES correctly

Total Hit ( 2504)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
'This was a killer i saw it in the MSDN libraries and they went to
'much deep into it but there is an easier way...it works better
'In Visual basic 5.0 or 6.0 you cann'ot sort by date in the listview.
'The problem is that when a value is entered in the cell, the control
'treats it as text. To overcome this problem, I created a extra column
'and set its width to zero so it would not be visible at run time.
'I then modify the date format so it will appear evenly and as a number
'starting from year then month last day.
     
'i.e.
lvListItems.SubItems(10) = Year(Search_Recordset.Fields("UPDATEDATE")) & _
  Format$(Month(Search_Recordset.Fields("UPDATEDATE")), "0#") & _
  Format$(Day(Search_Recordset.Fields("UPDATEDATE")), "0#")
     
'     Gave me: 20010110 from 1/10/2001
'19951214       From 12 / 14 / 1995
'19991101       From 11 / 1 / 1999
     
'The EVEN number lenghts will cause them to sort correctly as text.
'When the user clicked on the visible column, I just switched the column
'index to the hidden one.
     
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As ComctlLib.ColumnHeader)
  ListView1.SortKey = ColumnHeader.Index - 1
  If ListView1.SortKey = 1 Then lvwDisp.SortKey = 3 ' **** This column changes the key
  ListView1.SortOrder = (ListView1.SortOrder - 1) * -1
  ListView1.Sorted = True
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.