Solved

No 'check' property for Menustrip DropDownItems created at runtime

Posted on 2014-11-21
2
145 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with sorting data in Listbox using VB.NET 3 62
vb.net checkbox 7 47
Run a batch file when a Crystal Report is opened 5 27
Get the selected ValueMember of Combobox 5 30
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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