How to add a bind list to a list

I would like to add BindingList from CheckBoxes to listBox, here is the code I wrote:

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 name


    }
} 

      

when I click the add button on my forms, the checkboxes in my list are displayed like this: invcisible CheckBoxes in my ListBox

If I have to write the above code for BindingList String objects, then the system behavior is the same as expected. What am I doing wrong?

+3


source to share





All Articles