|
-
Mar 27th, 2003, 04:08 AM
#1
Thread Starter
Addicted Member
set contextmenu to selected items in listbox?
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
-
Mar 27th, 2003, 02:12 PM
#2
Frenzied Member
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
-
Mar 27th, 2003, 02:18 PM
#3
Sleep mode
I don't know if this would be another idea but you could try something like this
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
This suppose to show the menu when selected item is true .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|