+ Reply to Thread
Results 1 to 6 of 6

How do I deselect an item from a ListBox

  1. #1
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    326

    How do I deselect an item from a ListBox

    Hi,

    How do I deselect an item from a ListBox?

    I've attached a basic example where the user can select a ListBox item and a UserForm pops up depending upon which ListBox selection was made. However, once the UserForm is closed, the selected item that launched it should be deselected.

    I've tried inserting ListIndex = -1 into the ListBox code, but it doesn't work. (I've commented the line out because it requires the "OK" command button in the UserForm to be clicked twice in order to execute a form unload.)

    What do you think is going wrong?

    Lawrence
    Attached Files Attached Files
    Last edited by skysurfer; 10-27-2010 at 11:00 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do I deselect an item from a ListBox

    Hello skysurfer,

    You need to set the value of the Selected property to False.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    326

    Re: How do I deselect an item from a ListBox

    Hi Lieth,

    Thanks. I inserted your code as seen below (and newly attached file), but it does not deselect the item in the list and for some weird reason it causes the OK buttons on the UserForm (that simply unload the form) to require a double click.

    Did I insert your code in the wrong place?

    Please Login or Register  to view this content.
    Lawrence
    Attached Files Attached Files
    Last edited by skysurfer; 10-26-2010 at 06:45 PM.

  4. #4
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    326

    Re: How do I deselect an item from a ListBox

    Just bumping this up. Spent hours scouring the Web for the answer...seems Lieth's solution is dead on simple, but I keep messing it up somehow.

    Lawrence

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419

    Re: How do I deselect an item from a ListBox

    Try moving the code to the MouseUp event in order to avoid the cascading events caused by clicking and setting the listindex value.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    326

    Re: How do I deselect an item from a ListBox

    Thank you, Andy.

    Lawrence

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1