Right click event on ComboBox

H

Hardik Shah

Hi,

I want to create menu , when my user right click from combo box's list item.
I use Contextmenu property of combobox and assign menu for it, but it only
effected when combobox's list item not active. When my user on any
combobox's item and he right click the mouse , menu doesn't appear.

How to create menu.

Thanks in advance.

Hardik Shah.
 
J

Josef Brunner

Hi,

this code works for my listBox:
(myFormMenuItemDelete and myFormMenuItemEdit must be defined as context menu
items)

' Only act on the right-button-click event to display the context menu

If e.Button = Windows.Forms.MouseButtons.Right Then

Try

Dim myListViewItem As ListViewItem = myFormListView.GetItemAt(e.X, e.Y)

' Only if the user clicked on a valid ListViewItem

If Not myListViewItem Is Nothing Then

myFormMenuItemDelete.Enabled = True

myFormMenuItemEdit.Enabled = True

myIndex= myListViewItem.Index()

Else

' The user did not richt-click on one of the ListView items

myFormMenuItemDelete.Enabled = False

myFormMenuItemEdit.Enabled = False

End If

Catch ex As Exception

myFormMenuItemDelete.Enabled = False

myFormMenuItemEdit.Enabled = False

MsgBox(ex.ToString)

End Try

End If

Hope this helps,

Josef
 
H

Hardik Shah

Hi,
First of all thanks for your reply.

Can you tell me how can I use your code (with which event).

Hardik Shah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top