Question Can listbox contain buttons?

groadsvb

Well-known member
Joined
Nov 13, 2006
Messages
75
Programming Experience
Beginner
I am working on this app and decided to add a listbox to the form since a listbox can contain objects. The objects I decided to add are buttons. When I launch my app. I see the listbox and what appears to be where the buttons are but no text is being displayed. Maybe I am missing the point of the listbox. Can I have buttons in the listbox and have the text display for the bottons?
 
A ListBox can contain any objects you like but what it displays is String representations of those objects. If you add Buttons to a ListBox then, just like any other object, the ListBox will call ToString on them to get a String representation that it can display.

If you want a column of Buttons then you should probably do one of two things:

1. Add a TableLayoutPanel to your form and then Add your Buttons to its Controls collection.
2. Add a DataGridView to your form with a DataGridViewButtonColumn in it.
 
Back
Top