Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help With A Listview (Excel 2K VBA)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Need Help With A Listview (Excel 2K VBA)

    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. It would have to be adapted to work on a userform in Excel.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Need Help With A Listview (Excel 2K VBA)

    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.

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need Help With A Listview (Excel 2K VBA)

    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,

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Need Help With A Listview (Excel 2K VBA)

    Unfortunately, the code appears to pre-date my archives (archives of the daily digests of Word and VBA):
    <hr>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.<hr>
    Sorry to get your hopes up!

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

    1. <LI>Store value of ListItem n+1 (if moving down; n-1 if moving up) to strVariable
      <LI>Set value of ListItem n+1 (if moving down; n-1 if moving up) = value of ListItem n
      <LI>Set value of ListItem n = strVariable
      <LI>Change the selection to ListItem n+1 (if moving down; n-1 if moving up)
    Hope this helps.

  6. #6
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need Help With A Listview (Excel 2K VBA)

    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

    Deb

  7. #7
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need Help With A Listview (Excel 2K VBA)

    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,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •