private void okToolStripMenuItem_Click(object sender, EventArgs e) { try { string lname = dgv.Rows[0].Cells[2].Value.ToString(); string lcat = dgv.Rows[0].Cells[1].Value.ToString(); string lbar = dgv.Rows[0].Cells[0].Value.ToString(); double lprice; if (!(double.TryParse(dgv.Rows[0].Cells[3].Value.ToString(), out lprice))) { lprice = 0; } Shop.AddGood(lname, lcat, lbar, lprice); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }