Need some help with vb StatusStrip Control

M

Marc

Hello,



I have a vb.net form that I've added a StatusStrip at the bottom. On that
StatusStrip I've added a DropDownButton on which I've added a Menu
containing 4 sub Items



What I am trying to do is cycle through the Menu's subitems one by one and
uncheck or check the items instead of setting them all individually.



So, here's what I want to avoid:



Private Sub SubToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles SubToolStripMenuItem1.Click

SubToolStripMenuItem.Checked = False
SubToolStripMenuItem1.Checked = False
SubToolStripMenuItem2.Checked = False
SubToolStripMenuItem3.Checked = True

End Sub



My DropDownButton is called: ToolStripDropDownButton1

My Menu that contains the 4 sub items is called: MyToolStripMenuItem

My sub items are: SubToolStripMenuItem, SubToolStripMenuItem1,
SubToolStripMenuItem2, SubToolStripMenuItem3



I've googled groups until my eyes have bled and I can't find an answer. I'd
like to use something like this:



Dim MI as MenuItem

For each MI in MyMenu.MenuItems
MI.Checked = false
Next
CType(sender, MenuItem).Checked = true



The problem is that I can't find a way to attach to the menu and get a hold
of each menu items .checked property.



Any ideas or pointers would be very helpful. I am trying to move from VB6
to .net and am having some headaches along the way.



Thanks,



Marc
 
H

Homer J Simpson

What I am trying to do is cycle through the Menu's subitems one by one and
uncheck or check the items instead of setting them all individually.

I was watching some of "Fahrenheit 451" on TV today. "Burn all the books,
they only make you unhappy". Hmmm, makes you think.

Here is some lousy code:

Dim thing
For Each thing In ToolStripDropDownButton1.DropDownItems
thing.checked = False
Next
 
M

Marc

Hey,

Thank you for the code, I tried it and found out it is only affecting the
DropDownButton menu but not the Sub ToolStripMenuItems. Let me see if I can
ASCII art what's happening here:

DropDownButton1
|
-TestToolStripMenuItem (Code below checks this menu when I set
thing.checked = true)
|
-- Test1ToolStripMenuItem
-- Test2ToolStripMenuItem
-- Test3ToolStripMenuItem
-- Test4ToolStripMenuItem
|
-TestTwoToolStripMenuItem (Code below checks this menu when I set
thing.checked = true)

So, here I have two main menus off of DropDownButton1. One menu called
"Test", the other called "Test two". The menu "Test" has sub items inside
it labeled "Test1", "Test2", "Test3" and "Test4". These Menu Items are the
ones I'm trying to check and uncheck. Your code below works perfectly to
check or uncheck the two "Top Level" menus on the button but not the
subitems.

The problem is trying to get to the subitme(s).checked property - I'm at a
loss here. and that's why in each subitems clicked event I've had to
hard-code this mess:

Private Sub Test1ToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles Test1ToolStripMenuItem.Click

Test1ToolStripMenuItem.Checked = True
Test2ToolStripMenuItem.Checked = False
Test3ToolStripMenuItem.Checked = False
Test4ToolStripMenuItem.Checked = False

End Sub
 
H

Homer J Simpson

Thank you for the code, I tried it and found out it is only affecting the
DropDownButton menu but not the Sub ToolStripMenuItems. Let me see if I
can ASCII art what's happening here:

You will probably need to figure out which collection these items are in and
then access it via that collection and its members. That seems to be the way
things work now.
 
G

gene kelley

Hello,



I have a vb.net form that I've added a StatusStrip at the bottom. On that
StatusStrip I've added a DropDownButton on which I've added a Menu
containing 4 sub Items



What I am trying to do is cycle through the Menu's subitems one by one and
uncheck or check the items instead of setting them all individually.



So, here's what I want to avoid:



Private Sub SubToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles SubToolStripMenuItem1.Click

SubToolStripMenuItem.Checked = False
SubToolStripMenuItem1.Checked = False
SubToolStripMenuItem2.Checked = False
SubToolStripMenuItem3.Checked = True

End Sub



My DropDownButton is called: ToolStripDropDownButton1

My Menu that contains the 4 sub items is called: MyToolStripMenuItem

My sub items are: SubToolStripMenuItem, SubToolStripMenuItem1,
SubToolStripMenuItem2, SubToolStripMenuItem3



I've googled groups until my eyes have bled and I can't find an answer. I'd
like to use something like this:



Dim MI as MenuItem

For each MI in MyMenu.MenuItems
MI.Checked = false
Next
CType(sender, MenuItem).Checked = true



The problem is that I can't find a way to attach to the menu and get a hold
of each menu items .checked property.



Any ideas or pointers would be very helpful. I am trying to move from VB6
to .net and am having some headaches along the way.



Thanks,



Marc
I'm not all that sure what you are trying to accomplish, but if you
are simply trying to ensure that only the currently selected menu item
is checked, you can do this:
(Uses default names, VB2005)

In each MenuItem_Click Event add these two lines:
ClearChecks()
CType(sender, ToolStripMenuItem).Checked = True

Add this Sub:

Private Sub ClearChecks()
Dim MI As ToolStripMenuItem
For Each MI In Me.ToolStripDropDownButton1.DropDownItems
MI.Checked = False
Next
End Sub

Gene
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top