Reference to added user control

  • Thread starter Thread starter adh
  • Start date Start date
A

adh

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.Controls(.Controls.Count - 1), _ myUserControl)
doesn't go.

Thanks, adh
 
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.count - 1 to 0
if TypeOf me.controls(i) Is myUserControl then
return me.controls(i)
end if
next
///

I hope this helps,

Cor
 
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
 
Thanks Cor,
I Thought about it, but I still need a Ctype when trying to access or
copy emmbeded controls.

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).myproperty
Two Questions are left:
1) Why doesn't Me.Controls.Add(uctl) return a reference (like all "Add"s
do)?

I don't know what you mean by this.
2) Why are we going backwards, things of 1 codding line are becomming a
whole routine?
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
 

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

Back
Top