VB[2008] For each loop using an Array of type ToolStripItemCollection

  • Thread starter Thread starter Rob W
  • Start date Start date
R

Rob W

Greetings,

I originally had THREE for/each loops to cycle around each toolstripitem for
of the three toolstripmenuitem.dropdownlists.

I then thought could I use an array of toolstripitemcollection to include
all contents of the toolstripmenuitem.dropdownlists.

Dim myThreeMenuItems() As ToolStripItemCollection =
{myParent.EditToolStripMenuItem.DropDownItems,
myParent.ToolsToolStripMenuItem.DropDownItems,
myParent.WindowsToolStripMenuItem.DropDownItems}


Note: Myparent is due to this being an MDI application.

Dim myMenuItem As ToolStripItem

For Each myEditMenuItem In myThreeMenuItems

myMenuItem.Enabled = False

Next

How can this be achieved?

I get confused with the current error as it states the for each loop is
invalid due to differing types involved (menuitem vs itemcollection).

Surely an Item can reference an item collection?


Thanks
Rob
 
Rob W said:
Greetings,

I originally had THREE for/each loops to cycle around each toolstripitem
for of the three toolstripmenuitem.dropdownlists.

I then thought could I use an array of toolstripitemcollection to include
all contents of the toolstripmenuitem.dropdownlists.

Dim myThreeMenuItems() As ToolStripItemCollection =
{myParent.EditToolStripMenuItem.DropDownItems,
myParent.ToolsToolStripMenuItem.DropDownItems,
myParent.WindowsToolStripMenuItem.DropDownItems}


Note: Myparent is due to this being an MDI application.

Dim myMenuItem As ToolStripItem

For Each myEditMenuItem In myThreeMenuItems

myMenuItem.Enabled = False

Next

How can this be achieved?

Does this work?

for each col in myThreeMenuItems
For Each myEditMenuItem as toolstripitem In col
myEditMenuItem.Enabled = False
Next
next


An option is writing a function doing the (inner) loop. Call it three times
and pass one collection each time.


Armin
 
Worked a treat, having done the logic to loop through a toolstripmenuitem I
should have realised how to apply this for toolstripitemcollection.

Cheers (workign code below)
:-)

'Declare ToolStrip Item objects for each set of toolstripmenuitems items

Dim menu As ToolStripItemCollection

Dim menuitem As ToolStripItem

Dim myThreeMenuItems() As ToolStripItemCollection = _

{myParent.EditToolStripMenuItem.DropDownItems, _

myParent.ToolsToolStripMenuItem.DropDownItems, _

myParent.WindowsToolStripMenuItem.DropDownItems}


If myParent.MdiChildren.Length = 1 Then

For Each Menu In myThreeMenuItems

'Disable ALL Items in the THREE ToolstripMenuItems Edit, Tools and Window

For Each menuitem In Menu

menuitem.Enabled = False

Next

Next

End If
 
Back
Top