Reference to added user control

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

    #1

    Reference to added user control

    Hello,
    How do I get the referebce to the last added UserControl:
    Me.Controls.Add (myUserControl)
    When I add one after another?

    Return CType(Me.Contro ls(.Controls.Co unt - 1), _ myUserControl)
    doesn't go.

    Thanks, adh

    *** Sent via Developersdex http://www.developersdex.com ***
  • Cor Ligthert [MVP]

    #2
    Re: Reference to added user control

    Just check it back ways up in the place your added it, if it is direct on a
    form by instance roughly typed in this message

    \\\
    for i as integer = me.controls.cou nt - 1 to 0
    if TypeOf me.controls(i) Is myUserControl then
    return me.controls(i)
    end if
    next
    ///

    I hope this helps,

    Cor

    "adh" <adh@devx.com > schreef in bericht
    news:eXOWg7UuFH A.444@TK2MSFTNG P15.phx.gbl...[color=blue]
    > Hello,
    > How do I get the referebce to the last added UserControl:
    > Me.Controls.Add (myUserControl)
    > When I add one after another?
    >
    > Return CType(Me.Contro ls(.Controls.Co unt - 1), _ myUserControl)
    > doesn't go.
    >
    > Thanks, adh
    >
    > *** Sent via Developersdex http://www.developersdex.com ***[/color]


    Comment

    • adh

      #3
      Re: Reference to added user control

      Thanks Cor,
      I Thought about it, but I still need a Ctype when trying to access or
      copy emmbeded controls.

      Two Questions are left:
      1) Why doesn't Me.Controls.Add (uctl) return a reference (like all "Add"s
      do)?
      2) Why are we going backwards, things of 1 codding line are becomming a
      whole routine?

      Thanks, adh

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Reference to added user control

        > Thanks Cor,[color=blue]
        > I Thought about it, but I still need a Ctype when trying to access or
        > copy emmbeded controls.[/color]

        You need a CType or a directcast if you need a property that you have
        yourself added.

        dim mytext as string = ctr(x).text
        dim mySpecial as string = directcast(ctr( x),mycontrol).m yproperty
        [color=blue]
        >
        > Two Questions are left:
        > 1) Why doesn't Me.Controls.Add (uctl) return a reference (like all "Add"s
        > do)?[/color]

        I don't know what you mean by this.
        [color=blue]
        > 2) Why are we going backwards, things of 1 codding line are becomming a
        > whole routine?
        >[/color]
        How do you know that a usercontrol is the last. If you are sure of that,
        than it is just

        me.controls(me. controls.count-1)

        I hope this helps,

        Cor


        Comment

        Working...