By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

Reference to a control error. Toolstrip

P: n/a
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


Jun 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
Terry
"Manekurt" wrote:
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


Jun 28 '06 #2

P: n/a
Thank you terry, it worked Perfectly!!!

"Terry" <Te***@nospam.nospam> escribió en el mensaje
news:00**********************************@microsof t.com...
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.
--
Terry
"Manekurt" wrote:
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


Jun 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.