Results 1 to 3 of 3

Thread: set contextmenu to selected items in listbox?

  1. #1

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179

    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

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I don't know if this would be another idea but you could try something like this

    VB Code:
    1. Private Sub ListBox1_SelectedIndexChanged(ByVal sender As _
    2. System.Object, ByVal e As System.EventArgs) Handles
    3. ListBox1.SelectedIndexChanged
    4.  
    5. If ListBox1.SelectedItem.ToString() <> "" Then
    6.             'show your contextmenu
    7. End If
    8.  
    9.     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
  •  



Click Here to Expand Forum to Full Width