private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         product.Name     = Name.Text;
         product.Price    = Double.Parse(Price.Text);
         product.Quantity = int.Parse(Quantity.Text);
         using (Produse2Entities pd = new Produse2Entities())
         {
             pd.Entry(product).State = System.Data.Entity.EntityState.Modified;
             pd.SaveChanges();
             ListDataGridView();
             MessageBox.Show("Edited");
         }
     }
     catch (InvalidCastException)
     {
         MessageBox.Show("Invalid Price");
     }
     catch (FormatException)
     {
         MessageBox.Show("Invalid Data");
     }
     catch (OverflowException)
     {
         MessageBox.Show("Invalid Quantity");
     }
 }
 private void Delete_Click(object sender, EventArgs e)
 {
     using (Produse2Entities pd = new Produse2Entities())
     {
         var entrances = pd.Entry(product);
         if (entrances.State == System.Data.Entity.EntityState.Detached)
         {
             pd.Products4.Attach(product);
         }
         pd.Products4.Remove(product);
         pd.SaveChanges();
         ListDataGridView();
         Reset();
         MessageBox.Show("Deleted");
     }
 }