private void dgvCategory_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex == -1) { return; } try { if (e.ColumnIndex == 5) { Int32 categoryID = Convert.ToInt32("0" + dgvCategory.Rows[e.RowIndex].Cells[0].Value); UpdateCategoryCtl objUpdate = new UpdateCategoryCtl(categoryID); objUpdate.Parent = this.ParentForm; UserControlManager.UserControls.Push(this); Panel pnl = (Panel)this.ParentForm.Controls["pnlContext"]; string s = pnl.Name; objUpdate.ParentForm.Controls[s].Controls.Clear(); objUpdate.ParentForm.Controls[s].Controls.Add(objUpdate); } else if (e.ColumnIndex == 6) { if (MessageBox.Show("Are you sure you want to delete the selected category?", RMSGlobal.MessageBoxTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int parentCatId = 0; bool bTempBool = Int32.TryParse(dgvCategory.Rows[e.RowIndex].Cells[0].Value.ToString(), out parentCatId); if (bTempBool) { CCategory2 oCat = new CCategory2(); oCat.Category2ID = parentCatId; CCategoryManager oManager = new CCategoryManager(); CResult oResult = oManager.DeleteCat2(oCat); if (oResult.IsSuccess) { dgvCategory.Rows.RemoveAt(e.RowIndex); } } } } } catch (Exception exp) { throw exp; } }