Reference to a control error. Toolstrip

M

Manekurt

Hello to everyone, I have this code, that gives me an error on the marked
line. It is to make a reference to a submenuitem, to enable it thorgh it
name.
Error line:

For Each oSubitem As ToolStripMenuItem In oSubmenuItems

error: Message="No se puede convertir un objeto de tipo = Can´t convert
the type of object
'System.Windows.Forms.ToolStripSeparator' to type
'System.Windows.Forms.ToolStripMenuItem'."



If anyone knows how to solve this, it would be of great help

Thank you

Manek





Private Sub mkgv2_container_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.RecorrerEstructuraMenu(Me.men_principal,
mk_sqlre_2("sec_per_cat").ToString)

End Sub



Private Sub RecorrerEstructuraMenu(ByVal oMenu As MenuStrip, ByVal sOpcion
As String)

For Each oOpcionMenu As ToolStripMenuItem In oMenu.Items



If oOpcionMenu.DropDownItems.Count > 0 Then

Me.RecorrerSubmenu(oOpcionMenu.DropDownItems, sOpcion)

End If

Next

End Sub

Private Sub RecorrerSubmenu(ByVal oSubmenuItems As ToolStripItemCollection,
ByVal sOpcion As String)


For Each oSubitem As ToolStripMenuItem In oSubmenuItems 'ERROR
LINE'||||||||||||||||||||||||||

If oSubitem.Name = sOpcion Then

oSubitem.Enabled = True

End If

If oSubitem.DropDownItems.Count > 0 Then

Me.RecorrerSubmenu(oSubitem.DropDownItems, sOpcion)

End If

Next

End Sub
 
G

Guest

The ToolStripItemCollection is a collection of 'ToolStripItem' not
'ToolStripMenuItems'. So maybe something like this (and I am not sure of
this part)...

For Each oSubitem As ToolStripItem In oSubmenuItems
if TypeOf oSubItem Is ToolStripMenuItem Then
...
The point being that a ToolStripSeperator is a ToolStripItem but not a
ToolStripMenuItem.
 
M

Manekurt

Thank you terry, it worked Perfectly!!!

Terry said:
The ToolStripItemCollection is a collection of 'ToolStripItem' not
'ToolStripMenuItems'. So maybe something like this (and I am not sure of
this part)...

For Each oSubitem As ToolStripItem In oSubmenuItems
if TypeOf oSubItem Is ToolStripMenuItem Then
...
The point being that a ToolStripSeperator is a ToolStripItem but not a
ToolStripMenuItem.
 

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