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

menustrip
sql_oracle
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
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
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.LoadmCMSBuild.Items.Add(BuildBadItemsSubMenuItem())
End Sub Private Function BuildBadItemsSubMenuItem() As ToolStripMenuItem 'Build the Bad Items SubMenu... Dim itemCollection(2) As ToolStripMenuItemitemCollection(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 SubAll 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
like so :
AddHandler MenuObj.click, AddressOf MyClickEventHandler
Remco
alevy
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
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 5BadItemsToolStripMenuItem.DropDownItems.Add(
"A -" + t.ToString) NextEnd Sub
End
ClassWhen 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
Carl