|
-
Dec 21st, 2002, 02:17 PM
#1
Thread Starter
Member
Menu Items in the Main Menu [RESOLVED]
How can I write code to uncheck ALL of the checked menu items that are in a Main Menu?
Here is the code that I tried: (which doesn't work)
Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
cpnum = 3
Dim i As Integer
Dim mnu As MainMenu = Me.MainMenu1
For i = 1 To 20
MainMenu1.MenuItems.Item(i).Checked = False
Next
MenuItem8.Checked = True
End Sub
Thanks,
Jared.
Last edited by Jared; Dec 22nd, 2002 at 09:35 AM.
-
Dec 21st, 2002, 02:54 PM
#2
yay gay
try with a foreach instead...also what did u get with that code that u wrote?
\m/  \m/
-
Dec 21st, 2002, 03:16 PM
#3
Thread Starter
Member
An error stating that "This is only valid for MenuItems that have no children and are not top-level."
Also the above code should have been:
Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
Dim i As Integer
Dim mnu As MainMenu = Me.MainMenu1
For i = 1 To 20
mnu.MenuItems.Item(i).Checked = False
Next
MenuItem7.Checked = True
End Sub
But it did not change anything.
-
Dec 21st, 2002, 04:16 PM
#4
Sleep mode
try this
VB Code:
Dim mnu As New MainMenu()
-
Dec 21st, 2002, 08:38 PM
#5
A mainmenu kind of works like a treeview where children of a parent can have children and on and on. So you have to have a recursive function to check all the generations.
VB Code:
'syntax of use
UncheckAll(Me.MainMenu1.MenuItems)
Public Sub UncheckAll(ByVal mnu As MainMenu.MenuItemCollection)
Dim mi As MenuItem
'checks each item in this collection
For Each mi In mnu
If mi.Checked Then mi.Checked = False
'checks any children of this item
'this will always be called to make sure it checks all generations
UncheckAll(mi.MenuItems)
Next
End Sub
-
Dec 22nd, 2002, 09:34 AM
#6
Thread Starter
Member
Thanks Edneeis, that worked like a charm. I knew there was an easier way to uncheck all the menu items, just couldn't get it to work correctly. I had an extremely long list of redundant code to accomplish this task (but now I can delete it! ).
- Jared.
-
Dec 22nd, 2002, 04:55 PM
#7
Hyperactive Member
(before reading this post, i must admit that i've had a huge weekend on the piss, and am not feeling the best for a monday morning)
edneeis, is it possible to have
Code:
UncheckAll(mi.MenuItems)
called from inside itself? looking at it, to me it seems circular.
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Dec 22nd, 2002, 06:34 PM
#8
Pardon? I don't think I understand the question.
Are you asking if UncheckAll can be called from within itself? If so then yes you can do that.
As far as circular, not exactly but it is recursive. It doesn't call itself with the same parameters repeatibly. It calls itself on the collection of the current item in the current collection it is checking. This is intentional so that all of the nodes and their children get checked.
-
Dec 23rd, 2002, 02:41 AM
#9
Hyperactive Member
Edneeis,
yes, I was unsure if a sub-routine could call itself. when i first looked at it, i thought that it would get stuck in a loop and only stop when the call stack memory got too large. now i'm awake and focuessed, it makes sense.
thanks
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|