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

Comparing a control with another control's parent

P: n/a
Hi I have an app that has a number of textboxes (richtextboxes to be exact)
that get created dynamically and I add a few at a time to panel controls (so
I can flip a group in and out when I want). So the textbox objects get
added to the panel object like so:

panelObj.Controls.Add(textboxObj)

And then I store the panel Objects in a linked list so I can sort through
them later.

Each texbox I create I setup a Handler to trap any time a user leaves the
box like so:
AddHandler tb.Leave, AddressOf CellEvent_Leave
My CellEvent_Leave method looks like so:
Private Sub CellEvent_Leave(ByVal sender As Object, ByVal e As
System.EventArgs)

As I traverse the linked list, I am comparing the Panel Objects I stored
with the sender of the event's parent like so:

If (panelObj Is sender.parent) Then

But this is never evaluating to true, even though I can trace both panelObj
and sender.parent and see I'm looking at the same objects.

I'm thinking this may be some sort of pointer issue. Perhaps there is a
copy being made somewhere. Should I be comparing these in a different way,
or is something wrong in what I'm trying to do. Is there a better way to
trap events on dynamically created controls like I'm doing?


Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
Mark Denardo wrote:
Hi I have an app that has a number of textboxes (richtextboxes to be exact)
that get created dynamically and I add a few at a time to panel controls (so
I can flip a group in and out when I want). So the textbox objects get
added to the panel object like so:

panelObj.Controls.Add(textboxObj)

And then I store the panel Objects in a linked list so I can sort through
them later.

Each texbox I create I setup a Handler to trap any time a user leaves the
box like so:
AddHandler tb.Leave, AddressOf CellEvent_Leave
My CellEvent_Leave method looks like so:
Private Sub CellEvent_Leave(ByVal sender As Object, ByVal e As
System.EventArgs)

As I traverse the linked list, I am comparing the Panel Objects I stored
with the sender of the event's parent like so:

If (panelObj Is sender.parent) Then

But this is never evaluating to true, even though I can trace both panelObj
and sender.parent and see I'm looking at the same objects.

I'm thinking this may be some sort of pointer issue. Perhaps there is a
copy being made somewhere. Should I be comparing these in a different way,
or is something wrong in what I'm trying to do. Is there a better way to
trap events on dynamically created controls like I'm doing?



I'm a bit confused on why you are storing the link list?

Sender.Parent will tell you what panel it is on. Sender.Parent.Controls
will give you all the controls that are in that panel.

Chris
Nov 21 '05 #2

P: n/a
Okay disregard this message. I had another layer of controls (TabPages)
that the panels were sitting on, that were very similar (including text)
that I had mistakenly flip flopped and thus they were not the same. I
corrected the problem and they compare like I was hoping.

Chris to answer your question, the panels themselves weren't a link list,
but class objects were being link listed together - that contain a bunch of
information on each panel plus a pointer to the panel object itself. Plus
each object is related to the object before and after it, so I need to keep
them in order. If I could somehow store a pointer to my class objects in
the panel object it would make my life easier when doing a lookup of the
class information related to the panel object.


"Chris" <no@spam.com> wrote in message
news:ej**************@TK2MSFTNGP15.phx.gbl...
Mark Denardo wrote:
Hi I have an app that has a number of textboxes (richtextboxes to be
exact) that get created dynamically and I add a few at a time to panel
controls (so I can flip a group in and out when I want). So the textbox
objects get added to the panel object like so:

panelObj.Controls.Add(textboxObj)

And then I store the panel Objects in a linked list so I can sort through
them later.

Each texbox I create I setup a Handler to trap any time a user leaves the
box like so:
AddHandler tb.Leave, AddressOf CellEvent_Leave
My CellEvent_Leave method looks like so:
Private Sub CellEvent_Leave(ByVal sender As Object, ByVal e As
System.EventArgs)

As I traverse the linked list, I am comparing the Panel Objects I stored
with the sender of the event's parent like so:

If (panelObj Is sender.parent) Then

But this is never evaluating to true, even though I can trace both
panelObj and sender.parent and see I'm looking at the same objects.

I'm thinking this may be some sort of pointer issue. Perhaps there is a
copy being made somewhere. Should I be comparing these in a different
way, or is something wrong in what I'm trying to do. Is there a better
way to trap events on dynamically created controls like I'm doing?



I'm a bit confused on why you are storing the link list?

Sender.Parent will tell you what panel it is on. Sender.Parent.Controls
will give you all the controls that are in that panel.

Chris

Nov 21 '05 #3

P: n/a
Mark,

A little simple advice, try to set in top of your program or in your options

Option Strict On

That will probably help you a lot with this kind of questions.

Cor
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.