I have a ListBox in winforms , C# application.
i need to add to the ListBox CheckBoxes in the code , and i need that HorizontalScrollbar will appear when there is a lot of CheckBoxes and the ListBox can’t show them all.
I have placed the ListBox on the Window and set it’s HorizontalScrollbar to be true. Also i have set the maximum height and width for the ListBox.But when i run the application , i can’t see all the CheckBoxes…
can anyone help with that?
this the code for adding the checkboxes :
listBox1.HorizontalScrollbar = true;
this.groupBox_ChooseTCPipConfg.Controls.Add(listBox1);
CheckBox chk1 = new CheckBox();
chk1.Text = "chk1";
chk1.Location = new Point(2, 2);
listBox1.Controls.Add(chk1);
CheckBox chk2 = new CheckBox();
chk2.Text = "chk2";
chk2.Location = new Point(2,22);
listBox1.Controls.Add(chk2);
CheckBox chk3 = new CheckBox();
chk3.Text = "chk3";
chk3.Location = new Point(2, 42);
listBox1.Controls.Add(chk3);
CheckBox chk4 = new CheckBox();
chk4.Text = "chk4";
chk4.Location = new Point(2, 62);
listBox1.Controls.Add(chk4);
CheckBox chk5 = new CheckBox();
chk5.Text = "chk5";
chk5.Location = new Point(2, 82);
listBox1.Controls.Add(chk5);
CheckBox chk6 = new CheckBox();
chk6.Text = "chk6";
chk6.Location = new Point(2, 102);
listBox1.Controls.Add(chk1);
CheckBox chk7 = new CheckBox();
chk7.Text = "chk7";
chk7.Location = new Point(2, 122);
listBox1.Controls.Add(chk7);
CheckBox chk8 = new CheckBox();
chk8.Text = "chk8";
chk8.Location = new Point(2, 142);
listBox1.Controls.Add(chk8);
CheckBox chk9 = new CheckBox();
chk9.Text = "chk9";
chk9.Location = new Point(2, 162);
listBox1.Controls.Add(chk9);
CheckBox chk10 = new CheckBox();
chk10.Text = "chk10";
chk10.Location = new Point(2,202);
listBox1.Controls.Add(chk10);
when i run the application , i can only see the first 7 checkboxes….
You dont’ have
ListBoxscroll because you didn’t add any items to it. You just place theCheckBoxcontrols inside. Scroll appears oly if you will have to many items.For such purposes use
FlowLayoutPanelcontrol.Here is how properties should be set for
FlowLayoutPanel