Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Controls
  New Posts New Posts RSS Feed - ListView Sorting
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ListView Sorting

 Post Reply Post Reply
Author
Message
jgordon428 View Drop Down
Groupie
Groupie


Joined: 11 June 2009
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote jgordon428 Quote  Post ReplyReply Direct Link To This Post Topic: ListView Sorting
    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.
Back to Top
stkPablo View Drop Down
Newbie
Newbie
Avatar

Joined: 07 December 2009
Location: Argentina
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote stkPablo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
ampcom View Drop Down
Groupie
Groupie


Joined: 20 September 2008
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote ampcom Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
dentor View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2005
Location: France
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote dentor Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
ampcom View Drop Down
Groupie
Groupie


Joined: 20 September 2008
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote ampcom Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Aaron View Drop Down
Senior Member
Senior Member
Avatar

Joined: 29 January 2008
Status: Offline
Points: 2192
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Quote  Post ReplyReply Direct Link To This Post 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....
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.189 seconds.