private void button1_Click(object sender, EventArgs e) { prod = new Product(); AddEditForm addForm = new AddEditForm(prod, true); if (addForm.ShowDialog() == DialogResult.OK) { listBox1.Items.Add(prod); } }
private void button2_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex == -1) { MessageBox.Show("Product no chose"); return; } int n = listBox1.SelectedIndex; prod = (Product)listBox1.Items[n]; AddEditForm editFrom = new AddEditForm(prod, false); editFrom.ShowDialog(); listBox1.Items.RemoveAt(n); listBox1.Items.Insert(n , prod); listBox1.SelectedIndex = n; }