So I have a collection that I have in a listbox right now, which displays each item in the collection. I want to turn the listbox into a gridview, so I can add checkboxes and other drop downs. I am unable to find a tutorial that explains how to do this.
For the example my collection has 2 items, each item has multiple columns.
- [0] 747 Jet
- [0] Passenger amount: 417
- [1] First Flight: 1967
- [0] A380
- [0] Passenger amount: 853
- [1] First Flight: 2005
Right now my listbox uses this code
foreach (AMAPnr.Airplane airElement in AMAPnr.Airplanes)
{
lstPlanes.Items.Add(
"PassengerAmount: " + airElement.Passenger + " First Flight:" +
airElement.FirstFlight.ToString());
}
How would i go about changing this into a gridview?
Update: The OP has clarified that they chose the wrong tags and this was actually for WinForms.
If you add a
DataGridViewto your form, and then put the following code in your forms codebehind, it works a treat:I’ve used a custom Airplane class to show this example a I don’t know precisely how your code’s structured and it was easier for me that way. You should be able to plug in your custom datatype relatively easily.