Consulting

Results 1 to 5 of 5

Thread: Deselecting double clicked item in listbox

  1. #1

    Deselecting double clicked item in listbox

    Hi, I have a question regarding the DblClick Event in VBA Excel.

    Basically, what I am trying to do is:
    1. Trigger the DblClick event when an item in a multiselect listbox is double clicked
    2. At the end of the event, I would like to deselect all items in the listbox including the item that was double clicked.

    Now I have no problems with #1, but I am struggling with #2.

    This is what I tried doing:

    [VBA]Sub lb1_DblClick()

    ...... (several statements which runs ok)


    'End of event - deselect all
    For i = 0 To lb1.ListCount - 1
    lb1.Selected = False
    Next i
    End Sub
    [/VBA]
    Now this does deselect all the items in the listbox but the "square" remains around the clicked item, and it seems this is because I am still in the DblClick event. Anyway to get rid of this square?


    FYI: The reason I am asking this seemingly unnecessary issue is because I am trying to repopulate this listbox with a SQL query to an Access DB at the end of the event and this seems to be interferring with the repopulation macro.

  2. #2
    Maybe helps.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Have you just tried setting ListIndex to -1?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thank you for your responses!

    omnibuster > That is essentially what I tried doing, but the rectangle still remains around the option that is double clicked.

    xls > I have tried setting ListIndex to -1 - this doesn't work because it's a MultiSelect listbox.

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Try changing this line
    [VBA]lb1.Selected(i) = False[/VBA]

Posting Permissions

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