PDA

View Full Version : Deselecting double clicked item in listbox



akidragon
02-07-2010, 09:23 PM
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:

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

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.

omnibuster
02-08-2010, 12:51 AM
Maybe helps.

Bob Phillips
02-08-2010, 02:31 AM
Have you just tried setting ListIndex to -1?

akidragon
02-10-2010, 02:07 AM
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.

mikerickson
02-10-2010, 02:52 AM
Try changing this line
lb1.Selected(i) = False