Reference to a control error. Toolstrip

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manekurt

    #1

    Reference to a control error. Toolstrip

    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 ToolStripMenuIt em In oSubmenuItems

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



    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.EventArg s) Handles MyBase.Load

    Me.RecorrerEstr ucturaMenu(Me.m en_principal,
    mk_sqlre_2("sec _per_cat").ToSt ring)

    End Sub



    Private Sub RecorrerEstruct uraMenu(ByVal oMenu As MenuStrip, ByVal sOpcion
    As String)

    For Each oOpcionMenu As ToolStripMenuIt em In oMenu.Items



    If oOpcionMenu.Dro pDownItems.Coun t > 0 Then

    Me.RecorrerSubm enu(oOpcionMenu .DropDownItems, sOpcion)

    End If

    Next

    End Sub

    Private Sub RecorrerSubmenu (ByVal oSubmenuItems As ToolStripItemCo llection,
    ByVal sOpcion As String)


    For Each oSubitem As ToolStripMenuIt em In oSubmenuItems 'ERROR
    LINE'|||||||||| ||||||||||||||| |

    If oSubitem.Name = sOpcion Then

    oSubitem.Enable d = True

    End If

    If oSubitem.DropDo wnItems.Count > 0 Then

    Me.RecorrerSubm enu(oSubitem.Dr opDownItems, sOpcion)

    End If

    Next

    End Sub




  • Terry

    #2
    RE: Reference to a control error. Toolstrip

    The ToolStripItemCo llection is a collection of 'ToolStripItem' not
    'ToolStripMenuI tems'. So maybe something like this (and I am not sure of
    this part)...

    For Each oSubitem As ToolStripItem In oSubmenuItems
    if TypeOf oSubItem Is ToolStripMenuIt em Then
    ...
    The point being that a ToolStripSepera tor is a ToolStripItem but not a
    ToolStripMenuIt em.
    --
    Terry


    "Manekurt" wrote:
    [color=blue]
    > 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 ToolStripMenuIt em In oSubmenuItems
    >
    > error: Message="No se puede convertir un objeto de tipo = Can´t convert
    > the type of object
    > 'System.Windows .Forms.ToolStri pSeparator' to type
    > 'System.Windows .Forms.ToolStri pMenuItem'."
    >
    >
    >
    > 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.EventArg s) Handles MyBase.Load
    >
    > Me.RecorrerEstr ucturaMenu(Me.m en_principal,
    > mk_sqlre_2("sec _per_cat").ToSt ring)
    >
    > End Sub
    >
    >
    >
    > Private Sub RecorrerEstruct uraMenu(ByVal oMenu As MenuStrip, ByVal sOpcion
    > As String)
    >
    > For Each oOpcionMenu As ToolStripMenuIt em In oMenu.Items
    >
    >
    >
    > If oOpcionMenu.Dro pDownItems.Coun t > 0 Then
    >
    > Me.RecorrerSubm enu(oOpcionMenu .DropDownItems, sOpcion)
    >
    > End If
    >
    > Next
    >
    > End Sub
    >
    > Private Sub RecorrerSubmenu (ByVal oSubmenuItems As ToolStripItemCo llection,
    > ByVal sOpcion As String)
    >
    >
    > For Each oSubitem As ToolStripMenuIt em In oSubmenuItems 'ERROR
    > LINE'|||||||||| ||||||||||||||| |
    >
    > If oSubitem.Name = sOpcion Then
    >
    > oSubitem.Enable d = True
    >
    > End If
    >
    > If oSubitem.DropDo wnItems.Count > 0 Then
    >
    > Me.RecorrerSubm enu(oSubitem.Dr opDownItems, sOpcion)
    >
    > End If
    >
    > Next
    >
    > End Sub
    >
    >
    >
    >
    >[/color]

    Comment

    • Manekurt

      #3
      Re: Reference to a control error. Toolstrip

      Thank you terry, it worked Perfectly!!!

      "Terry" <Terry@nospam.n ospam> escribió en el mensaje
      news:0081E6A6-C9D4-4D55-9C1D-E9105DC08DD5@mi crosoft.com...[color=blue]
      > The ToolStripItemCo llection is a collection of 'ToolStripItem' not
      > 'ToolStripMenuI tems'. So maybe something like this (and I am not sure of
      > this part)...
      >
      > For Each oSubitem As ToolStripItem In oSubmenuItems
      > if TypeOf oSubItem Is ToolStripMenuIt em Then
      > ...
      > The point being that a ToolStripSepera tor is a ToolStripItem but not a
      > ToolStripMenuIt em.
      > --
      > Terry
      >
      >
      > "Manekurt" wrote:
      >[color=green]
      >> 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 ToolStripMenuIt em In oSubmenuItems
      >>
      >> error: Message="No se puede convertir un objeto de tipo = Can´t convert
      >> the type of object
      >> 'System.Windows .Forms.ToolStri pSeparator' to type
      >> 'System.Windows .Forms.ToolStri pMenuItem'."
      >>
      >>
      >>
      >> 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.EventArg s) Handles MyBase.Load
      >>
      >> Me.RecorrerEstr ucturaMenu(Me.m en_principal,
      >> mk_sqlre_2("sec _per_cat").ToSt ring)
      >>
      >> End Sub
      >>
      >>
      >>
      >> Private Sub RecorrerEstruct uraMenu(ByVal oMenu As MenuStrip, ByVal
      >> sOpcion
      >> As String)
      >>
      >> For Each oOpcionMenu As ToolStripMenuIt em In oMenu.Items
      >>
      >>
      >>
      >> If oOpcionMenu.Dro pDownItems.Coun t > 0 Then
      >>
      >> Me.RecorrerSubm enu(oOpcionMenu .DropDownItems, sOpcion)
      >>
      >> End If
      >>
      >> Next
      >>
      >> End Sub
      >>
      >> Private Sub RecorrerSubmenu (ByVal oSubmenuItems As
      >> ToolStripItemCo llection,
      >> ByVal sOpcion As String)
      >>
      >>
      >> For Each oSubitem As ToolStripMenuIt em In oSubmenuItems 'ERROR
      >> LINE'|||||||||| ||||||||||||||| |
      >>
      >> If oSubitem.Name = sOpcion Then
      >>
      >> oSubitem.Enable d = True
      >>
      >> End If
      >>
      >> If oSubitem.DropDo wnItems.Count > 0 Then
      >>
      >> Me.RecorrerSubm enu(oSubitem.Dr opDownItems, sOpcion)
      >>
      >> End If
      >>
      >> Next
      >>
      >> End Sub
      >>
      >>
      >>
      >>
      >>[/color][/color]


      Comment

      Working...