private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e) { if (dataGridView1.SelectedRows.Count == 0) { return; } frmEditItem frm = new frmEditItem(); frm.funLoad(); frm.ItemName = dataGridView1.SelectedRows[0].Cells["Name"].Value.ToString(); frm.ItemType = dataGridView1.SelectedRows[0].Cells["Type"].Value.ToString(); if (frm.ShowDialog() == DialogResult.Yes) { dataGridView1.SelectedRows[0].Cells["Name"].Value = frm.ItemName; dataGridView1.SelectedRows[0].Cells["Type"].Value = frm.ItemType; } if (!frm.IsDisposed) { frm.Close(); frm.Dispose(); } }
private void funAddItem() { frmEditItem frm = new frmEditItem(); frm.funLoad(); if (frm.ShowDialog() == DialogResult.Yes) { DataRow dr = dt.NewRow(); dr.BeginEdit(); dr["Name"] = frm.ItemName; dr["Type"] = frm.ItemType; dr.EndEdit(); dt.Rows.Add(dr); dataGridView1.DataSource = null; dataGridView1.DataSource = dt; } if (!frm.IsDisposed) { frm.Close(); frm.Dispose(); } }