private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
            {
                MessageBox.Show("Enter all fields");
            }
            else
            {
                if (prod == null)
                {
                    prod = new Product();
                }

                prod.Title = textBox1.Text;
                prod.Producer = textBox2.Text;
                try
                {
                    prod.Price = Convert.ToDouble(textBox3.Text);
                }
                catch(Exception ex)
                {
                    MessageBox.Show("Price entered incorrect" + ex.Message);
                    return;
                }
                this.DialogResult = DialogResult.OK;
            }
        }
 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;
        }
        public AddEditForm(Product _prod , bool _addNew)
        {
            InitializeComponent();

            addNew = _addNew;
            prod = _prod;

            if (!addNew)
            {
                textBox1.Text = prod.Title;
                textBox2.Text = prod.Producer;
                textBox3.Text = prod.Price.ToString();
                this.Text = "Editing";
            }
            else
            {
                this.Text = "Adding";
            }
        }