Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi, EveryOne!
I have a user control that contains two controls:
    1. Button
    2. CheckedListBox

Currently I want to add the item to checkdedlistbox from main form.
this is possible?
Any comments or suggestions are very grateful!
Thank you!

Environment: Visual studio express 2013 for desktop
Language: C#.
Platforms: Winform
Posted
Comments
Suvendu Shekhar Giri 29-Jun-15 6:55am    
5* for a clear question. :)
StackThanh 29-Jun-15 11:29am    
Thank you for the answers!

1 solution

you can give the usercontol the functions/properties you need

C#
public partial class MyUserControl : UserControl
  {
    public MyUserControl()
    {
      InitializeComponent();
    }

    public int CheckedListBoxAddItems(object item)
    {
      return checkedListBox1.Items.Add(item);
    }

  }
}


and then call them from your form code

C#
protected override void OnLoad(EventArgs e)
{
  base.OnLoad(e);
  myUserControl1.CheckedListBoxAddItems("item1");
  myUserControl1.CheckedListBoxAddItems("item2");
  myUserControl1.CheckedListBoxAddItems("item3");
}
 
Share this answer
 
Comments
StackThanh 29-Jun-15 12:30pm    
Thank you very much!
Your support is very helpful for me!
Closed solution!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900