I would like to add a BindingList of CheckBoxes into a listBox,here is the code that i have written:
public partial class Form1 : Form
{
BindingList<CheckBox> chBoxBList = new BindingList<CheckBox>();
public Form1()
{
InitializeComponent();
}
private void addBtn_Click(object sender, EventArgs e)
{
CheckBox chBox = new CheckBox();
chBox.Height = 20;
chBox.Text = "Task" + chBoxBList.Count.ToString();
chBox.ForeColor = Color.Black;
chBox.BackColor = Color.Gray;
chBoxBList.Add(chBox);
lBox.DataSource = chBoxBList;//lBox is my ListBox's name
}
}
when I press the add button in my forms the Checkboxes in my Listbox appear as follows:
If I am to write the above given code for a BindingList of String objects then the behavior of the system is as desired and expected. What am I doing wrong?