Custom Control Inheritance




I have a (kind of a newbie) question:

I want to create one custom control which has a ListBox control in it.
Then I want to inherit that control and instead of the ListBox I want
to use CheckedListBox (but with the same object name). I know that
CheckedListBox inherits from the ListBox control, but I'm not sure if I
can (and how) use that feature in this particular case.

To make it more clear I will explain what exactly I want to do:

This will be a simple admin application for a Examination system. It
will be used to create a list of test questions. One control will
store a list of questions, the other one will store answers for a given
question. The only difference will be that the list of answers would
have a checkbox beside each answer to indicate if the answer is true
(there will be couple more items in that control but they will be the
same for both controls).

Thanks in advance for any suggestions.




You probably won't be able to use the VS designer to control this behaviour.
Instead, I would create either the ListBox or the CheckedListBox manually
right after the InitializeComponent call, based on some flag that you pass
onto your control.
Since CheckedListBox is derived from ListBox, you can share most of the
events and properties and set them to common values. For the CheckedListBox,
you will need to attach additional events and maybe some properties to
control the clicking on the checkmarks.

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