• Need Help With A Listview (Excel 2K VBA)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Need Help With A Listview (Excel 2K VBA)

    Author
    Topic
    #397399

    Hello,

    I have a listview on a userform and I would like to be able to move items up and down the list with a command button. I tried adjusting the Index property, but that is a read only property.

    Can any one tell me how to move an item up or down in a listview using a command button?

    Thanks

    Viewing 5 reply threads
    Author
    Replies
    • #752304

      I fear that this requires an intimate knowledge of Windows API calls. Brad Martinez has an example for VB6 on the WMVP site: http://www.mvps.org/btmtz/treeview/tvnodemove.zip%5B/url%5D. It would have to be adapted to work on a userform in Excel.

    • #752305

      I fear that this requires an intimate knowledge of Windows API calls. Brad Martinez has an example for VB6 on the WMVP site: http://www.mvps.org/btmtz/treeview/tvnodemove.zip%5B/url%5D. It would have to be adapted to work on a userform in Excel.

    • #752395

      I don’t have an answer, but I’m curious about the control you’re using. Is the “listview” different than the ListBox that comes with VBA’s MSForms library? Long ago there was a thread on how to sort a ListBox which might have provided some tips on how to reshuffle the contents without completely clearing and re-populating it. However, before digging around for that, I thought I’d better ask what control you’re actually using.

      • #752419

        The listview is not the same as a listbox. Although, considering what I am using the Listview for, a ListBox may be a suitable replacement. If you know of any code that would allow me to move one or more items up or down the list of a listbox, I would to have a look at it.

        Thanks,

        • #752457

          Unfortunately, the code appears to pre-date my archives (archives of the daily digests of Word and VBA):[indent]


          Subject: Re: Sorting a listbox in VBA (Word 2000) [#176751]
          Poster: jscher2000
          Posted on: 07-Sep-02 00:36

          The common methods are to put your data in an array and sort that using WordBasic.SortArray, or to sort the items directly in the control using a custom function. If you go back to the posts from 2001, I think you will find a couple of different ways to sort the listbox without using the WordBasic.SortArray method.


          [/indent]Sorry to get your hopes up!

          But isn’t this just a three-step drill?

          1. Store value of ListItem n+1 (if moving down; n-1 if moving up) to strVariable
          2. Set value of ListItem n+1 (if moving down; n-1 if moving up) = value of ListItem n
          3. Set value of ListItem n = strVariable
          4. Change the selection to ListItem n+1 (if moving down; n-1 if moving up)

          Hope this helps.

        • #752458

          Unfortunately, the code appears to pre-date my archives (archives of the daily digests of Word and VBA):[indent]


          Subject: Re: Sorting a listbox in VBA (Word 2000) [#176751]
          Poster: jscher2000
          Posted on: 07-Sep-02 00:36

          The common methods are to put your data in an array and sort that using WordBasic.SortArray, or to sort the items directly in the control using a custom function. If you go back to the posts from 2001, I think you will find a couple of different ways to sort the listbox without using the WordBasic.SortArray method.


          [/indent]Sorry to get your hopes up!

          But isn’t this just a three-step drill?

          1. Store value of ListItem n+1 (if moving down; n-1 if moving up) to strVariable
          2. Set value of ListItem n+1 (if moving down; n-1 if moving up) = value of ListItem n
          3. Set value of ListItem n = strVariable
          4. Change the selection to ListItem n+1 (if moving down; n-1 if moving up)

          Hope this helps.

      • #752420

        The listview is not the same as a listbox. Although, considering what I am using the Listview for, a ListBox may be a suitable replacement. If you know of any code that would allow me to move one or more items up or down the list of a listbox, I would to have a look at it.

        Thanks,

    • #752396

      I don’t have an answer, but I’m curious about the control you’re using. Is the “listview” different than the ListBox that comes with VBA’s MSForms library? Long ago there was a thread on how to sort a ListBox which might have provided some tips on how to reshuffle the contents without completely clearing and re-populating it. However, before digging around for that, I thought I’d better ask what control you’re actually using.

    • #752938

      If you have John Walkenbach’s book “Excel 2000 Power Programming with VBA”, he has samples of how to just what you ask. This is the THE best VBA book in my opinion. There are samples of how to have a form with list boxes and two buttons like ‘move up’ and ‘move down’ which let the user sort the items in the list. Also you can have two list boxes with buttons that let the user move an item from list1 to list2 (like they’d use to include or exclude a list of items for some other purpose).

      I gotta leave for work right now but can copy the code from the book later if you want. See John’s web site at http://www.j-walk.com/ss%5B/url%5D

      Deb

      • #752948

        Actualy I do have this book and I agree with you that it is the best Excel VBA book out there. I will check it out to see if it has what I need.

        Thanks,

      • #752949

        Actualy I do have this book and I agree with you that it is the best Excel VBA book out there. I will check it out to see if it has what I need.

        Thanks,

    • #752939

      If you have John Walkenbach’s book “Excel 2000 Power Programming with VBA”, he has samples of how to just what you ask. This is the THE best VBA book in my opinion. There are samples of how to have a form with list boxes and two buttons like ‘move up’ and ‘move down’ which let the user sort the items in the list. Also you can have two list boxes with buttons that let the user move an item from list1 to list2 (like they’d use to include or exclude a list of items for some other purpose).

      I gotta leave for work right now but can copy the code from the book later if you want. See John’s web site at http://www.j-walk.com/ss%5B/url%5D

      Deb

    Viewing 5 reply threads
    Reply To: Need Help With A Listview (Excel 2K VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: