Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2005, 01:21 AM
Authorized User
 
Join Date: Jan 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to JelfMaria
Default Sorting a ListView

I have a listview in Report view style.
I want to sort that listview with any specific column header,
How's it possible ?

or atleast can someone tell me how to sort a 1 column listview in reportview style?

Thanks
Jelfy
__________________
Thanks
Jelfy
 
Old June 7th, 2005, 01:52 AM
Authorized User
 
Join Date: Jan 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to JelfMaria
Default

:DThank God

I got the answer for a single column listview sorting.
Its like this :

Sorting Items

To make the list view sort its items when the user clicks on a column header, use this code in the ListView_ColumnClick event.

With ListView1 '// change to the name of the list view
    Static iLast As Integer, iCur As Integer
    .Sorted = True
    iCur = ColumnHeader.Index - 1
    If iCur = iLast Then .SortOrder = IIf(.SortOrder = 1, 0, 1)
    .SortKey = iCur
    iLast = iCur
End With

Simple!

But how to sort based on a column when we have multiple column headers,can anyone help?



Thanks
Jelfy
 
Old June 10th, 2005, 05:46 AM
Authorized User
 
Join Date: Jan 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to JelfMaria
Default

Sorry friends,its not becoz of that coding sorting a single column list view worked .it worked only becoz i have given under sorting tab---sorted-- true and key--0.

But can any one say how to sort based on any column in a multicoulm report view of listview control?

Thanks
Jelfy
 
Old June 10th, 2005, 01:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this work for me, with a listView named lstData, that is basically the same of the code you posted...
Marco

Private Sub lstData_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    On Error Resume Next
    If lstData.SortKey = ColumnHeader.index - 1 Then
        If lstData.SortOrder = lvwAscending Then
            lstData.SortOrder = lvwDescending
        Else
            lstData.SortOrder = lvwAscending
        End If
    Else
        lstData.SortOrder = lvwAscending
        lstData.SortKey = ColumnHeader.index - 1
    End If
    ''SetSortIcon
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
ListView asters VB.NET 2002/2003 Basics 0 March 27th, 2008 05:00 AM
listView AristotleYu ASP.NET 2.0 Basics 0 May 11th, 2006 04:54 AM
listview sorting in VB 6.0 jthadathilm16 Pro VB 6 2 April 24th, 2006 02:31 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Listview Sorting adroc Pro VB 6 0 June 11th, 2003 01:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.