ListItemCollection for a listbox within a composite control

S

studen771

Thanks in advance to anyone who can help :)

First, you'll have to pardon my very 'beginner' status on custom controls..

I'm creating a composite control that includes a listbox, and i want to be
able to add/remove items within it both in design time and runtime, just as
the default listbox behaves in the vs.net designer.

The 'ListItemCollection' property is read-only, and thus I don't know how to
enable this functionality either in design time or runtime. I tried creating
a public propery of type 'ListItemCollection' within the composite control,
yet in the vs.net designer (design time) it ignores any additional items I
attempt to add to the listbox.

1 ) If I create a object derived from the Listbox control, can I achieve
this functionality? If so, how? OR ---
2) Can I simply do this within the existing composite control? If so how?

Also, some additional resources explaining the functionality of server
controls within composite controls would be greatly appreciated...

I've perused the internet quite a bit but there does not seem to be clear
explanations available.
 
C

Chris Taylor

Hi,

I do not do a terrible amount of web controls, but I would suggest you look
at exposing a property
of type ListItemCollection as you did and add the add the Editor attribute
something like the following:

[Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.InnerDefaultProperty),
MergableProperty(false)]
public virtual ListItemCollection Items
{
...
}

I have not tested this, but I hope it at least get you going in the right
direction.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top