CheckedListbox Control Items Add?

I have a Win app using a custom user control which contains a CheckedListbox.

Q. How can I add items to the custom control like: checkedListbox.Items.Add(...)?
pointemanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abelCommented:
What you should do is create an Add function or an Items property on your UserControl. Make it public, and have it pass the information on to your internal checkedListBox. The easiest, in fact, is something like the following (you don't need to create a "set", because you only want people to Add or Remove to the list, not replace the whole list at once with another one).

public CheckedListBox.ObjectCollection Items
{
    get
    {
        return checkedListBox.Items;
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abelCommented:
Then, in the calling application, someone can do something like:

myUserCtl.Items.Add("new item");
0
williamcampbellCommented:
Do you have the source code ... ?


 public void AddItemToListBox ( ListViewItem lvItem )
 {
    myCustomControl.GetListControl().Items.Add ( lvItem );
 }
 
 

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

pointemanAuthor Commented:
The first code you provided worked famously. What does your latest code do?
 public void AddItemToListBox ( ListViewItem lvItem )
{
    myCustomControl.GetListControl().Items.Add ( lvItem );
}
 
0
pointemanAuthor Commented:
opps, spoke to soon. I thought it was part of the actual control, but I see it access the control for items...
0
abelCommented:
The last code is not mine, it is williamcampbell's code. He assumes a different underlying control, but your control does not allow ListViewItems, not even ListItems. It only allows general objects (which could be ListViewItems, but I'm not sure that would work).

I'm not sure what you mean with your last statement. Do you mean it doesn't work for you anymore?
0
pointemanAuthor Commented:
This code works well:
public CheckedListBox.ObjectCollection Items { get { return checkedListBox.Items; } }
I have a new problem: The user control makes some labels and textboxes disappear in VS designer. Also cannot place more than one custom user control on win form without making eithor or both disappear.
 
0
abelCommented:
That's quite a different problem, I won't mind helping you there, but consider the one q. per thread principle from EE... The place where you should look is in the this.DesignMode (to distinguish design mode code to run mode code). Do you mean other controls that do not belong to this control? Sound like some repaint problem, or that the actual size of your user control (the canvas) is larger than it should be.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.