VB6 using a ListView control


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: VB6 using a ListView control

  1. #1
    Join Date
    Nov 2004
    Posts
    293

    VB6 using a ListView control

    I am putting information in a list view control using the listItems.add and that works fine however I would like to put the information in the list in reverse order, so that the first item is at the bottom of the list view and the last item is at the top. Can that be done durring the loading of the list or must the information be re-aranged prior to loading the list view ???

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    From what are you loading the listview?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Nov 2004
    Posts
    293
    I am just using a variable, I put the data in variable "a", "b", "c, etc then
    With LVMem
    .ListItems.Add , , a 'put the value in the List box column 1
    With .ListItems(LVMem.ListItems.Count)
    .SubItems(1) = b 'put the value in the List box col 2, column 2
    .SubItems(2) = c 'put the value in the List box col 3
    .SubItems(3) = d 'put the value in the List box col 4
    .SubItems(4) = e 'put the value in the List box col 5
    .SubItems(5) = F 'put the value in the List box col 6
    .SubItems(6) = g 'put the value in the List box col 7
    .SubItems(7) = h 'put the value in the List box col 7
    End With
    End With

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    If you are hard coding it, then the only manipulation available to you would be to hard code it in whatever order you want.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Nov 2004
    Posts
    293
    Not what I wanted to hear, but looks like the only way. Thanks for the help.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    If you wanted it to be available in both ascending and descending order, or some other kinds of orders, you could set each hard coded order up in a separate sub routine and call the appropriate one based on some kind of user selected.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  7. #7
    Join Date
    Jan 2009
    Location
    Saint Louis, MO
    Posts
    23
    You could always just sort after entry. Which view are you using in the listview? In the Report view, you can add code that sorts the data when a column header is clicked.

  8. #8
    Join Date
    Nov 2004
    Posts
    293
    that sounds interesting. Would that sort just that one column or sort all accordingly ?

  9. #9
    Join Date
    Jan 2009
    Location
    Saint Louis, MO
    Posts
    23
    It works just like an explorer window. If you select the detail view and then click the Type column, it sorts the files according to type.

  10. #10
    Join Date
    Nov 2004
    Posts
    293
    That sounds like an easy way, is there an example someplace ?

  11. #11
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    try this for sorting a listview
    Code:
    Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    ListView1.SortKey = ColumnHeader.Index - 1
    ListView1.Sorted = True
    ' toggle the sort order between ascending & descending
    ListView1.SortOrder = 1 Xor ListView1.SortOrder
    End Sub
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  12. #12
    Join Date
    Nov 2004
    Posts
    293
    I'll give it a try, thanks

  13. #13
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    It simply toggles the sort between ascending and descending.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  14. #14
    Join Date
    Jan 2009
    Location
    Saint Louis, MO
    Posts
    23
    This is what I use.

    Code:
    Private Sub lvw_ColumnClick(ByVal ColumnHeader As ColumnHeader)
       
        ' sort the listview on the column clicked
        With lvw
            If (.Sorted) And (ColumnHeader.SubItemIndex = .SortKey) Then
                If .SortOrder = lvwAscending Then
                    .SortOrder = lvwDescending
                Else
                    .SortOrder = lvwAscending
                End If
            Else
                .Sorted = True
                .SortKey = ColumnHeader.SubItemIndex
                .SortOrder = lvwAscending
            End If
            .Refresh
        End With
           
        ' If an item was selected prior to the sort,
        ' make sure it is still visible now that the sort is done.
        If Not lvw.SelectedItem Is Nothing Then
            lvw.SelectedItem.EnsureVisible
        End If
     
    End Sub
    When you click the column header the _ColumnClick event fires.
    When the column is clicked, if the column hasn't been sorted previously, it sorts ascending, otherwise it reverses the sort order.

    In the code, be sure that "lvw" is replaced with your listview name.

  15. #15
    Join Date
    Nov 2004
    Posts
    293
    OK, I've got the code in, I have it set up so that I call this sub from another sub, a simple Call but need a little help, in the part:
    Private Sub lvw_ColumnClick(ByVal ColumnHeader As ColumnHeader)

    what do I pass as the ColumnHeader ? is that the column number or column name or what??? Example: call lvw_ColumnClick(????I don't know what to put here???)

Similar Threads

  1. ListView control to view DBF files
    By badascan in forum VB Classic
    Replies: 1
    Last Post: 06-05-2007, 11:52 AM
  2. Selecting Data from a listview control
    By Mike Kraemer in forum VB Classic
    Replies: 3
    Last Post: 06-13-2002, 10:21 AM
  3. Filling columns in a listview control
    By Mike Kraemer in forum VB Classic
    Replies: 1
    Last Post: 05-29-2002, 07:36 PM
  4. ListView Control and Custom Sorting
    By Birhanu in forum VB Classic
    Replies: 0
    Last Post: 11-09-2001, 04:26 PM
  5. how to use the listView control
    By shachar in forum VB Classic
    Replies: 0
    Last Post: 07-12-2001, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center