Home All Groups Group Topic Archive Search About

Need some help with vb StatusStrip Control

Author
11 Mar 2006 8:39 PM
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

Author
11 Mar 2006 11:54 PM
Homer J Simpson
"Marc" <m***@home.com> wrote in message
news:%23DukUvURGHA.5036@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
Author
12 Mar 2006 12:33 AM
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



"Homer J Simpson" <nob***@nowhere.com> wrote in message
news:5rJQf.22616$vC4.10903@clgrps12...
Show quoteHide quote
>
> "Marc" <m***@home.com> wrote in message
> news:%23DukUvURGHA.5036@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
>
>
>
Author
12 Mar 2006 2:52 AM
Homer J Simpson
"Marc" <m***@home.com> wrote in message
news:%23jQUHyWRGHA.3052@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.
Author
12 Mar 2006 5:31 AM
Homer J Simpson
"Marc" <m***@home.com> wrote in message
news:%23jQUHyWRGHA.3052@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.
Author
12 Mar 2006 10:03 AM
gene kelley
Show quote Hide quote
On Sat, 11 Mar 2006 12:39:13 -0800, "Marc" <m***@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

Show quoteHide quote
>
>