menustrip

In my menustrip I have an item call "Bad Items"

when I click "bad items" my dropdowns appear (i add the dropdown items programmaticaly)

The question is, how can I assign to a variable the text in the dropdown when it's clicked.

Been messing with this all day and cant find the method.

Thx for any help!

Carl


Answer this question

menustrip

  • sql_oracle

    Either I'm not getting it or you're not getting what I am trying to do.

    On my Form I just have 1 menuitem called "Bad Items"

    then on form load I add 5 dropdownitems from an Array I created in a module.

    now, since I added them programmaticaly, I do not have an "On Click" handler, that is the whole problem.

    If I added them directly onto the form in design view, sure, I know how to handle that. But being that they are added programmatically, I do not know how to get an "On Click" to fire for those drop down items I added. I can get On Click to fire for the main one "Bad Items" but not for any of the drop downs.

    See

    Carl

  • fmiranda

    Tried to Plug this in to my program Grant, but no go.

    Like I said, I only used a menustrip control, looks like you have a couple of other things going on there I don't quite understand.

    I'll mess around with it some more at home, but this prog I need done for work so I'll hack a work around for now not using the menu strip. (button_1 to the rescue! :) )

    Thanks for the help.

    Carl

  • ccoe1

    Hey Zep,
    Don't know if this will help, but this is how I am managing my menu items.



    'Definition...

    Private WithEvents mCMSBuild As New ContextMenuStrip

    Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

    mCMSBuild.Items.Add(BuildBadItemsSubMenuItem())

    End Sub

    Private Function BuildBadItemsSubMenuItem() As ToolStripMenuItem

    'Build the Bad Items SubMenu...

    Dim itemCollection(2) As ToolStripMenuItem

    itemCollection(0) = New ToolStripMenuItem("Item1", _

    My.Resources.iconedittextdoc.ToBitmap, New EventHandler(AddressOf _

    Me.Item1OnClick))

    itemCollection(1) = New ToolStripMenuItem("Item2", _

    My.Resources.iconsearchweb.ToBitmap, New EventHandler(AddressOf _

    Me.Item2OnClick))

     

    itemCollection(2) = New ToolStripMenuItem("Item3", _

    My.Resources.iconquestion.ToBitmap, New EventHandler(AddressOf _

    Me.Item3OnClick))

    Dim subMenu As New ToolStripMenuItem("Bad Items", _

    My.Resources.icontextdoc.ToBitmap, itemCollection)

    Return subMenu

    End Function

    Private Sub Item1OnClick(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    Private Sub Item2OnClick(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    Private Sub Item3OnClick(ByVal sender As Object, ByVal e As EventArgs)

    End Sub


     



    All you need to do is add a Select Case or If statement around the line before the Return statement and change the name depending on which item you selected.

    Also add a MenuRefresh subroutine so you can dispose of the current menu and rebuild it.
     
    Regard,

    Grant.



  • harborsparrow

    addhandler


    like so :

    AddHandler MenuObj.click, AddressOf MyClickEventHandler

    Remco

  • alevy

    You're already making event handlers for the on click event, and that will send which item was click on.  (Me.Item3OnClick)

    there's 2 ways you can change their values.   1 By using the Sender Object, or 2, using the full name of the menustrip.

    Example...

    'Standard on click event for a menu strip.


        Private Sub BadItemsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BadItemsToolStripMenuItem.Click
            sender.text = "Hello"
        End Sub

     


    The other option, is to use the full name of the menu strip.  ...
    BadItemsToolStripMenuItem.Text = "Not Bad anymore"

    If on the other hand, you're looking to 'store' an object, in each menu strip for later use, then look at making a 2 dimensional array list.

    basically, an array of arraylists, and in each array, you have 2 items.  A Name, and a object.
    You can loop through the names, to find the one you need, then get the object  that's set in that array.




    Public Class Form1
        Dim Arr As ArrayList()

        Private Sub CreateMenuItems()
            ReDim Arr(10)

            Arr(0).Add("Menu1")
            Arr(0).Add(New Point(1, 1))

            Arr(1).Add("Menu2")
            Arr(1).Add(New Bitmap(10, 10, Imaging.PixelFormat.Format24bppRgb))
        End Sub

        Public Function GetMenuItem(ByVal sName As String)
            For i As Integer = 0 To arr.getupperbound(0)
                If Arr(i).Item(0) = sName Then Return Arr(i).Item(1)
            Next
            Return Nothing
        End Function
    End Class


     


    As long as the names of the menu items, match the names from the array as you put them in (You can do this when you're creating your menu objects), then you can get any item associated with it by calling "getMenuItem"  and passing it's name to the function.  It will return whatever object you set.

    Dustin.




  • RajCS

    An example with a menustrip1 added to the form and a "Bad Items" menu added to the menustrip, then on form load I add 5 dropdowns like below...


    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim t As Int16

    For t = 1 To 5

    BadItemsToolStripMenuItem.DropDownItems.Add("A -" + t.ToString)

    Next
    End Sub

    End Class


     



    When I run this, my 5 items are added as a dropdown to "Bad Items" on my menu, now when I click on dropdownmenu item "A-3" I want to assign the text of that dropdownmenu item
    (ie: "A-3" to a variable.) 

    Can anyone help me out

    Carl


  • kayuWoody

    Also, I do not know how many bad items will be added to the "Bad Items" could be 1 could be 2, could be 5.

    Carl

  • menustrip