private void button_AddCar_Click(object sender, EventArgs e) { try { Car_Inventory car = new Car_Inventory(); AssignCar(ref car); string str = car.Year.ToString() + " " + car.Make + " with" + " miles."; listBox_Display.Items.Add(str); } catch { MessageBox.Show("Provide wrong input"); comboBox_Make.Text = ""; comboBox_Year.Text = ""; comboBox_Milage.Text = ""; comboBox_Make.Focus(); } }
private void AssignCar(ref Car_Inventory car) { car.Make = comboBox_Make.SelectedItem.ToString(); car.Year = int.Parse(comboBox_Year.SelectedItem.ToString()); car.Mileage = int.Parse(comboBox_Milage.Text); }