Custom Controls and Constituant Controls 
Author Message
 Custom Controls and Constituant Controls

In my battles with databinding the stock ComboBox (in DropDown mode), I've
given myself toward creating a UserControl that incorporates this
functionality.

In inheriting, I've got two choices: inherit from ComboBox or inherit from
UserControl.

Inheriting from ComboBox SEEMS the best route, since it contains the
functionality I need.  However, I need to add a TextBox and position it
directly over the text portion of the base ComboBox.  I haven't been able to
make this work.

Inheriting from UserControl and adding a ComboBox and a TextBox is an easier
approach, as placing the TextBox over the ComboBox is much simpler.  However
I have to implement the properties of the ComboBox that I want to use, and
that's a bit of work.

My question:  Can one inherit from a base control (say ComboBox) and add a
constituent control to be visibly used as part of the new control?  Or do I
have to go the UserControl route??

Thanks,

--- Jim ---



Mon, 23 May 2005 02:34:30 GMT  
 Custom Controls and Constituant Controls
To just answer your question - yes you can just inherit from a base control
and add another control.  One way is to add the textbox in design mode and
ensure the designer has generated an InitializeComponent method and is
adding it to the controls collection; if not add it in yourself.

You may have to set the location and use Control.BringToFront to ensure it's
not behind the existing textbox.


Quote:
> In my battles with databinding the stock ComboBox (in DropDown mode), I've
> given myself toward creating a UserControl that incorporates this
> functionality.

> In inheriting, I've got two choices: inherit from ComboBox or inherit from
> UserControl.

> Inheriting from ComboBox SEEMS the best route, since it contains the
> functionality I need.  However, I need to add a TextBox and position it
> directly over the text portion of the base ComboBox.  I haven't been able
to
> make this work.

> Inheriting from UserControl and adding a ComboBox and a TextBox is an
easier
> approach, as placing the TextBox over the ComboBox is much simpler.
However
> I have to implement the properties of the ComboBox that I want to use, and
> that's a bit of work.

> My question:  Can one inherit from a base control (say ComboBox) and add a
> constituent control to be visibly used as part of the new control?  Or do
I
> have to go the UserControl route??

> Thanks,

> --- Jim ---



Mon, 23 May 2005 04:27:07 GMT  
 Custom Controls and Constituant Controls
OK Kollen...you hit the nail on the head...

The "automagically generated" code didn't add my constituent control to the
controls collection.  Once I did that, it's been easy to position and use
the base and its controls.  Thanks for the suggestion!

--- Jim ---


Quote:
> To just answer your question - yes you can just inherit from a base
control
> and add another control.  One way is to add the textbox in design mode and
> ensure the designer has generated an InitializeComponent method and is
> adding it to the controls collection; if not add it in yourself.

> You may have to set the location and use Control.BringToFront to ensure
it's
> not behind the existing textbox.



> > In my battles with databinding the stock ComboBox (in DropDown mode),
I've
> > given myself toward creating a UserControl that incorporates this
> > functionality.

> > In inheriting, I've got two choices: inherit from ComboBox or inherit
from
> > UserControl.

> > Inheriting from ComboBox SEEMS the best route, since it contains the
> > functionality I need.  However, I need to add a TextBox and position it
> > directly over the text portion of the base ComboBox.  I haven't been
able
> to
> > make this work.

> > Inheriting from UserControl and adding a ComboBox and a TextBox is an
> easier
> > approach, as placing the TextBox over the ComboBox is much simpler.
> However
> > I have to implement the properties of the ComboBox that I want to use,
and
> > that's a bit of work.

> > My question:  Can one inherit from a base control (say ComboBox) and add
a
> > constituent control to be visibly used as part of the new control?  Or
do
> I
> > have to go the UserControl route??

> > Thanks,

> > --- Jim ---



Mon, 23 May 2005 13:46:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Creating data-bound constituant control

2. Creating data-bound constituant control

3. user controls and custom controls

4. Cannot shift focus from custom control to other control

5. Focus of constituent control inside custom control

6. Control Arrays in Custom Controls

7. Here is a sample for custom control/composite control development

8. Creating Custom Controls in VBNet (not User Control, AFAIK)

9. Create a Custom Control (not a User Control, AFAIK)

10. Creating custom methods for a custom control

11. Raising Custom Active X Controls Events when using Data Repeater Control

12. Coolbar Control (Custom Controls 3)

 

 
Powered by phpBB® Forum Software