Hey,
I am creating a usercontrol, and I would like an Items property, like in ListView.Items.
How would I do this?
Cheers,
Jacob

Edit: I'm making a static menu, that won't disappear. Would it be better to just skin a listbox? There will be events for the items.

Hey there,
The thing you're asking is simple. All you have to do, in your UserControl, create some public properties that will interact with the ListView's properties:

public ListView.ListViewItemCollection Items
        {
            get
            {
                //Code for Getter   
            }

            set
            {
                //Code for Setter
            }

        }

Hope i helped :)

Hey,
I will edit the stuff like Add, Insert etc. I don't think that method will do that.
Cheers.

The methods and properties exposed by standard controls are no different from the methods and properties you write in code. If you want an Add method then add one to your control:

public void Add (object Item)
{
    myList.Items.Add(Item);
}

If the control you are creating is an extension of something that already exists then you can save yourself a lot of work by inheriting from it. For instance, if your menu is essentially going to be a listview with one or two custom behaviours then inherit from ListView and you will only need to add/override the behaviours unique to your control.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.