Solved

No 'check' property for Menustrip DropDownItems created at runtime

Posted on 2014-11-21
2
137 Views
Last Modified: 2014-11-21
Hi experts,

I need to add an array of menu dropdownitem at runtime to a menuitem created at design time.
The problem is: I can't find the property ‘check’  in my array of dropdownitem in its click event. I want the fired dropdownitem checked and all other dropdownitem in the same array uncheched.

Below is my code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For X = 0 To 5
            Dim NewMenuItem As New ToolStripMenuItem("Option" & X + 1, Nothing, New EventHandler(AddressOf Option_Click))
            NewMenuItem.Tag = X
            OptionToolStripMenuItem.DropDownItems.Add(NewMenuItem)
        Next
    End Sub

    Private Sub Option_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        For X = 0 To OptionToolStripMenuItem.DropDownItems.Count - 1
            OptionToolStripMenuItem.DropDownItems(X).BackColor = Color.White
          'want check property instead of highlighted with color
        Next
        OptionToolStripMenuItem.DropDownItems(sender.tag).BackColor = Color.Blue
    End Sub
0
Comment
Question by:LoGa1234567890
2 Comments
 
LVL 11

Accepted Solution

by:
louisfr earned 500 total points
ID: 40457053
Cast the item to the right type.
For example:
Dim menuItem = DirectCast(OptionToolStripMenuItem.DropDownItems(X), ToolStripMenuItem)
menuItem.Checked = True

Open in new window

0
 

Author Closing Comment

by:LoGa1234567890
ID: 40457083
Thank you !
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now