J
j_p_s
Hi all:
I found a trick that I thought I would share with anyone that could
benefit from it...
Basically I was trying to use a popup shortcut menu on a listbox in ony
of my forms. However, I also wanted to have the multi-select option
enabled. The trouble is that when you right click on a multi-select
listbox, the list then sets a single item selected where ever you right
clicked in the list.
Well... I love a good challange. I figured out that if you put a label
on your form, and then set the width to 0", you could set the focus to
it on the mouse down event of the list box when the button parameter is
2 (indicating a right click).
So basically what happens is, on a mouse down event, if the "Button"
parameter is a 2, then set the focus to the label. Because the label
has a width of 0", the user does not see that the focus has been passed
to another control. And because the focus has been changed, the on
click event never fires, and your list still has the multi items
selected. And bingo, the popup menu works, so you have all your list
items selected, and a right click shortcut menu.
Here is my on mouse down event code:
==========================================
Private Sub list_Contents_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'If right clicked, then set the focus to the focus point
If Button = 2 Then
'set the focus to my label with a 0" width
Me.FocusPoint.SetFocus
End If
End Sub
==========================================
The reason I am posting this is becaus I was looking for a solution for
this, and found that a few other people were also looking for a work
around for this.
Just thought I would share. = )
I found a trick that I thought I would share with anyone that could
benefit from it...
Basically I was trying to use a popup shortcut menu on a listbox in ony
of my forms. However, I also wanted to have the multi-select option
enabled. The trouble is that when you right click on a multi-select
listbox, the list then sets a single item selected where ever you right
clicked in the list.
Well... I love a good challange. I figured out that if you put a label
on your form, and then set the width to 0", you could set the focus to
it on the mouse down event of the list box when the button parameter is
2 (indicating a right click).
So basically what happens is, on a mouse down event, if the "Button"
parameter is a 2, then set the focus to the label. Because the label
has a width of 0", the user does not see that the focus has been passed
to another control. And because the focus has been changed, the on
click event never fires, and your list still has the multi items
selected. And bingo, the popup menu works, so you have all your list
items selected, and a right click shortcut menu.
Here is my on mouse down event code:
==========================================
Private Sub list_Contents_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'If right clicked, then set the focus to the focus point
If Button = 2 Then
'set the focus to my label with a 0" width
Me.FocusPoint.SetFocus
End If
End Sub
==========================================
The reason I am posting this is becaus I was looking for a solution for
this, and found that a few other people were also looking for a work
around for this.
Just thought I would share. = )