I’m creating a form in which the user inserts the name, brand and price of a product. These three are saved as properties of an object in a list of object, like this:
private void button1_Click(object sender, EventArgs e)
{
Product prod = new Product();
string kind = textBox1.Text;
prod.Kind = kind;
string brand = textBox2.Text;
prod.Brand = brand;
double price = Convert.ToDouble(textBox3.Text);
prod.Price = price;
listofthings.Add(prod);
}
What I want to do now is add a listbox in which the property ‘kind’ of each object is displayed, so the user can select specific products to buy.
i have tried
listBox2.DataSource = listofthings.prod.Kind;
but it won’t allow it.
A little help, please?
Bind listbox to your object, and set property
DisplayMemberto name of bound object’s property that you want to display in listbox: