Comparing a control with another control's parent

  • Thread starter Thread starter Mark Denardo
  • Start date Start date
M

Mark Denardo

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?
 
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.
 
Mark said:
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
 
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
 

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