ListView Sorting |
Post Reply |
Author | |
jgordon428
Groupie Joined: 11 June 2009 Status: Offline Points: 21 |
Post Options
Thanks(0)
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. |
|
stkPablo
Newbie Joined: 07 December 2009 Location: Argentina Status: Offline Points: 1 |
Post Options
Thanks(0)
|
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 |
|
ampcom
Groupie Joined: 20 September 2008 Status: Offline Points: 38 |
Post Options
Thanks(0)
|
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 |
|
SuperMario
Admin Group Joined: 14 February 2004 Status: Offline Points: 18057 |
Post Options
Thanks(0)
|
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 |
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
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 |
|
ampcom
Groupie Joined: 20 September 2008 Status: Offline Points: 38 |
Post Options
Thanks(0)
|
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 |
|
Aaron
Senior Member Joined: 29 January 2008 Status: Offline Points: 2192 |
Post Options
Thanks(0)
|
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.... |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |