How to add a bindinglist of checkboxes into a listbox

178 views Asked by At

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: invcisible CheckBoxes in my ListBox

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?

0

There are 0 answers