/// <summary> /// Save current row only in the DataGridView, no checks are made /// to detect if changes where made. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdEditCurrentRow_Click(object sender, EventArgs e) { if (MyDialogs.Question("Save current row")) { DataOperations DataOps = new DataOperations(); if (!(DataOps.UpdateRow(((DataRowView)bsCustomers.Current).Row))) { MessageBox.Show("Update failed"); } } }
/// <summary> /// Ask user if they want to add a new row /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == DataGridView1.NewRowIndex) { if (MyDialogs.Question("Add new row?") == false) { bsCustomers.CancelEdit(); bsCustomers.AllowNew = false; bsCustomers.AllowNew = true; SendKeys.Send("{UP}"); } } }
/// <summary> /// Delete current row if user replies yes. Note there is also /// DataOperations.RemoveRows not implemented but by following the instructions /// in RemoveRows you can implement this too. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdDeleteCurrentRow_Click(object sender, EventArgs e) { string CustomerName = ((DataRowView)bsCustomers.Current).Row.Field <string>("CompanyName"); if (MyDialogs.Question("Remove '" + CustomerName + "' record")) { DataOperations DataOps = new DataOperations(); if (DataOps.RemoveRow(((DataRowView)bsCustomers.Current).Row.Field <int>("Identifier"))) { bsCustomers.RemoveCurrent(); } else { MessageBox.Show("Failed to remove '" + CustomerName + "'"); } } }