Hi
Does anyone knows how to set contextmenu to selected items in listbox?, i know how you can do it with listview or treeview but the method does not seems to work in listbox
Thanks in advance
Printable View
Hi
Does anyone knows how to set contextmenu to selected items in listbox?, i know how you can do it with listview or treeview but the method does not seems to work in listbox
Thanks in advance
Don't take this as gospel or anything, I just wanted to try it - it seems to work. I would imagine someone more experienced could give you a better example. Hope it helps, anyway.
Code:Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Short
For i = 1 To 42
ListBox1.Items.Add("Item " & i)
Next
End Sub
Private Sub ContextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
ContextMenu1.MenuItems.Clear()
Dim selectedItems As New ListBox.SelectedObjectCollection(ListBox1)
Dim i As Short
For i = 0 To selectedItems.Count - 1
ContextMenu1.MenuItems.Add(selectedItems(i))
Next
End Sub
I don't know if this would be another idea but you could try something like this
This suppose to show the menu when selected item is true .VB Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged If ListBox1.SelectedItem.ToString() <> "" Then 'show your contextmenu End If End Sub