Print Page | Close Window

ListView Sorting

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=14513
Printed Date: 23 November 2024 at 8:22am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: ListView Sorting
Posted By: jgordon428
Subject: ListView Sorting
Date Posted: 11 June 2009 at 2:46pm
I'm using the Xtreme Suite Controls activeX version 13.0. I have a listview in a VB6 form. Is there a built-in mechanism (or code sample out there) for sorting based on column header click? My lists contain a mixture of string, date, and numeric data, and I need it to sort correctly based on the datatype. I figure I can store a code for the sort type in the columnheader tag property, but I'm not sure where I can pass the sort routine the specific sort type that I would like. Any suggestions?

Thank you.



Replies:
Posted By: stkPablo
Date Posted: 07 December 2009 at 7:53pm
Yo utyilizo el siguiente codigo:

Private Sub List_ColumnClick(ByVal ColumnHeader As XtremeSuiteControls.ListViewColumnHeader)
  List.SortKey = ColumnHeader.Index - 1
  If List.SortOrder = 0 Then List.SortOrder = 1 Else List.SortOrder = 0
  List.Sorted = True
End Sub



Posted By: ampcom
Date Posted: 28 April 2010 at 2:13am
Hi,
 
I am using the above example, but I cannot get to work with numeric values, i.e. when sorting ASC 10.21 will come before 9.21 - it seems to treat the columns as text values.
 
Does anyone know how to fix?
 
Regards
 
Tony
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.1
Platform: Windows 7 (64 Bit) Ultimate
Language: Visual Basic 6.0


Posted By: SuperMario
Date Posted: 28 April 2010 at 8:44am
Since our control is derived form standard MFC control it also lacks the ability to sort dates and numbers, but here is a great article that shows you how to do it, or you can do the add a dummy column idea one person suggests at the bottom.

http://www.codeguru.com/vb/controls/vb_listview/article.php/c1669


Posted By: dentor
Date Posted: 28 April 2010 at 12:53pm
Hello,
 
Here is a sample of Sub ListView1_ColumnClick which demonstrate a way of sorting numeric (integer) or date value with Listview control.
 
You save the older values in the Tag property, then put new formating values, do the sort, then put back the older values in the items.
The sample is for Numeric values in column 3 and date values in column 4
You can complete the sub to sort others types of values.
 
------------------------------------------------------------------------------------------------------------------------------------
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As XtremeSuiteControls.ListViewColumnHeader)
Dim Item As ListViewItem
 
    ' *** Numeric integer value in column 3
    ' *** Date value in column 4
    If ColumnHeader.Index = 3 Or ColumnHeader.Index = 4 Then
        For Each Item In Liste.ListItems
            Item.ListSubItems(ColumnHeader.Index - 1).Tag = Item.SubItems(ColumnHeader.Index - 1)
            Select Case ColumnHeader.Index
                Case 3
                    Item.SubItems(2) = right$(String$(12, "0") & Trim$(Item.ListSubItems(2)), 12)
                Case 4
                    Item.SubItems(3) = Format$(right$(Item.ListSubItems(3), 10), "yyyymmdd")
            End Select
        Next Item
    End If
 
    With ListView1
        .SortKey = ColumnHeader.Index - 1
        .Sorted = True
        .SortOrder = 1 Xor .SortOrder
    End With
   
    ' *** Put the value back in column 3 and 4
    If ColumnHeader.Index = 3 Or ColumnHeader.Index = 4 Then
        For Each Item In ListView1.ListItems
            Item.SubItems(ColumnHeader.Index - 1) = Item.ListSubItems(ColumnHeader.Index - 1).Tag
        Next Item
    End If
End Sub
-----------------------------------------------------------------------------------------------------------------------------
 
Hoping it will help you.
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 13.0.0
Platform: Windows XP (32bit) - SP 3
Language: Visual Basic 6.0 SP 6


Posted By: ampcom
Date Posted: 28 April 2010 at 3:20pm
Thanks to both of you, the example above works great - however the article has also solved another problem and is worth a read.
 
Regards
 
Tony
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.1
Platform: Windows 7 (64 Bit) Ultimate
Language: Visual Basic 6.0


Posted By: Aaron
Date Posted: 29 April 2010 at 12:32pm
Originally posted by ampcom ampcom wrote:

Thanks to both of you, the example above works great - however the article has also solved another problem and is worth a read.
 
Regards
 
Tony
 
 
Hi,
 
Did one of you ever used CJ ReportControl or ever try to use it? For me it was an easy decision to replace (in my case) MS Listview with CJ ReportControl. I don't have code to sort numeric values, it's sorted just by a click  
 
Just an idea...
 
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net