469,931 Members | 1,831 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,931 developers. It's quick & easy.

Need some help with vb StatusStrip Control

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


Mar 11 '06 #1
5 2872

"Marc" <ma**@home.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Mar 12 '06 #2
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

"Homer J Simpson" <no****@nowhere.com> wrote in message
news:5rJQf.22616$vC4.10903@clgrps12...

"Marc" <ma**@home.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Mar 12 '06 #3

"Marc" <ma**@home.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

Mar 12 '06 #4

"Marc" <ma**@home.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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:


http://samples.gotdotnet.com/quickstart/ might be worth a browse too.

Mar 12 '06 #5
On Sat, 11 Mar 2006 12:39:13 -0800, "Marc" <ma**@home.com> wrote:
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

Mar 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jim Hubbard | last post: by
2 posts views Thread by robertino | last post: by
6 posts views Thread by Jon Slaughter | last post: by
1 post views Thread by Carla Simeoni | last post: by
10 posts views Thread by hzgt9b | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.