3

I know I can use listBox.Controls.Add(new Button()); but I need to add several controls as rows, preferably from a List and set it as datasource. I have tried the following with no success:

var list = new List<Control>();

list.Add(new Button());
list.Add(new Button());
list.Add(new Button());

listBox1.DataSource = list;
0

3 Answers 3

4

I have decided to use a flowLayoutPanel instead. This seems like the best option right now.

Sign up to request clarification or add additional context in comments.

Comments

1

A ListBox is not designed to be a container control. Its scrollbar cannot scroll the controls. It is in general something you want to avoid, putting a lot of controls in, say, a Panel whose AutoScroll property is True will make your UI unresponsive. Controls are expensive objects.

4 Comments

what about DataGridView?
I found something on DataGridViews which is what you would want to do: stackoverflow.com/questions/7916919/… But to be honest; WPF is 10x more flexible to this type of program you want to write. Highly recommended
You could try to add the controls dynamically to the listbox; that will work for sure: social.msdn.microsoft.com/Forums/windows/en-US/…
yes but it only adds it to the first "row", not all the rows.
-2

I would advise you to use StackPanel instead of Listbox you can read about here also, you must add Button object in you list and in StackPanel like this:

Button b = new Button();
list.Add(b);
stackPanel.Children.Add(b);

so you can work with you buttons in stack panel via list

1 Comment

sorry, I didn't know that question about winforms:(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.