private void dgvWebsites_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { if (!IsAddingNewItem && !IsCellValueChanged) { return; } int colIndex = e.ColumnIndex; int rowIndex = e.RowIndex; IWebsite website = websites[rowIndex]; ValidationResult vr = ContextMenuEvent.Invoke(EventType.RowValidating, new ContextMenuEventArgs() { RowIndex = rowIndex, ColumnIndex = colIndex, Website = website }); if (!vr.IsSuccessfull) { ShowErrorMessage(vr.Message, "Error!"); e.Cancel = true; } else { IsAddingNewItem = false; IsCellValueChanged = false; } }
private void tsmiAdd_Click(object sender, EventArgs e) { if (ContextMenuEvent == null || !ContextMenuEvent.Invoke(EventType.BeginAdding, new ContextMenuEventArgs()).IsSuccessfull) { return; } dgvWebsites[0, dgvWebsites.Rows.Count - 1].Selected = true; IsAddingNewItem = true; dgvWebsites.BeginEdit(true); }
private void tsmiDelete_Click(object sender, EventArgs e) { int index = dgvWebsites.CurrentCell.RowIndex; ValidationResult vr = ContextMenuEvent.Invoke(EventType.Remove, new ContextMenuEventArgs() { RowIndex = index }); if (!vr.IsSuccessfull) { ShowErrorMessage(vr.Message, "Error!"); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { ContextMenuEvent.Invoke(EventType.Exit, new ContextMenuEventArgs()); }