Where is the proper place to set the parent property?

  • Thread starter Thread starter Joe Keller
  • Start date Start date
J

Joe Keller

Hello,

I'm creating a custom text control (derived from "TextBox") that in turn
creates a Combo Box control when the custom text control is instantiated.
If I attempt to set the parent of the Combo Box control during the "Create"
method of my custom Text Box, I get a NULL reference error telling me that
the "Parent" property of my Text Box control is NULL (which it indeed is at
this point). I got around this issue by overriding the "OnParentChanged"
method of my custom Text Box control and setting the parent property of my
Combo Box control within that method.

The question I have is, where is the proper place to set the parent properly
in this circumstance? Is there a better way than overriding the
"OnParentChanged" method?

I use the following code to set the parent of my Combo Box control to the
same parent of my Text Box control (remember, the Combo Box control is
instantiated from within the code of the Text Box control):

"this.Parent.Controls.Add(m_ComboBox);"

Thanks!

Joe
 
Thats a good plan. Thats really the best event your custom control can
subscribe on to do what you want to do.

-Ben

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| NNTP-Posting-Date: Sat, 18 Oct 2003 21:03:10 -0500
| From: "Joe Keller" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: Where is the proper place to set the parent property?
| Date: Sat, 18 Oct 2003 22:03:08 -0400
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Lines: 26
| NNTP-Posting-Host: 68.60.102.111
| X-Trace:
sv3-KjaaxJhrtIvFwdLUgyjZvrZURe66vQteRtg2g6U+7OX35GGUJ9BgN/Hw24tgJIONr2mbRvb6
WP1UN++!MLkIZh6Jm3Yzjrel+/UtL5X5D/jsL9lba3tk1c7t/jRuc0PQWF2B9pjwgef28w==
| X-Complaints-To: (e-mail address removed)
| X-DMCA-Complaints-To: (e-mail address removed)
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.1
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
m!tdsnet-transit!newspeer.tds.net!news-out1.nntp.be!propagator2-sterling!new
s-in-sterling.nuthinbutnews.com!cyclone1.gnilink.net!small1.nntp.aus1.gigane
ws.com!border1.nntp.aus1.giganews.com!intern1.nntp.aus1.giganews.com!nntp.gi
ganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:36316
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Hello,
|
| I'm creating a custom text control (derived from "TextBox") that in turn
| creates a Combo Box control when the custom text control is instantiated.
| If I attempt to set the parent of the Combo Box control during the
"Create"
| method of my custom Text Box, I get a NULL reference error telling me that
| the "Parent" property of my Text Box control is NULL (which it indeed is
at
| this point). I got around this issue by overriding the "OnParentChanged"
| method of my custom Text Box control and setting the parent property of my
| Combo Box control within that method.
|
| The question I have is, where is the proper place to set the parent
properly
| in this circumstance? Is there a better way than overriding the
| "OnParentChanged" method?
|
| I use the following code to set the parent of my Combo Box control to the
| same parent of my Text Box control (remember, the Combo Box control is
| instantiated from within the code of the Text Box control):
|
| "this.Parent.Controls.Add(m_ComboBox);"
|
| Thanks!
|
| Joe
|
|
|
 
Back
Top