With a question like this, I think it's good to consider whether "you really need this:" since a ListBox gives you the
equivalent of a 'Click Event for each of its Items in its 'SelectedIndexChanged EventHandler, why do you need Buttons ?
But, the simple answer to your question is "no." The WinForms ListBox is not able to accept internal WinForms Controls in a
useful way. It is true that code like this:
for (int i = 0; i < 10; i++)
{
string istr = i.ToString();
Button newButton = new Button();
newButton.Text = istr;
newButton.Name = "btn" + istr;
newButton.Visible = true;
newButton.BackColor = Color.AliceBlue;
newButton.ForeColor = Color.Black;
listBox1.Controls.Add(newButton);
newButton.Dock = DockStyle.Top;
newButton.BringToFront();
}
Would fill a ListBox with a bunch of Buttons; but all you would have done is created a mess that simulated a Panel full of Buttons ! You'd never be able to select any of the ListBox Items.
However, using a ListView, there are several work-arounds to inserting Controls; and CodeProject has several articles, and other resources on this if you do a little research; such as: [
^], [
^].
The best article, imho, on extending the ListView is Philip Piper's classic, ObjectListView: [
^].
A simpler solution would be to create a UserControl in which a ListBox, and a Panel (filled with Buttons) were combined. If you want to explore how to do this using a UserControl, you can ask for further details, and I will reply.
But, before you proceed further, I strongly suggest you re-evaluate if you really need both a ListBox and Buttons.