Solved

No 'check' property for Menustrip DropDownItems created at runtime

Posted on 2014-11-21
2
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

728 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