clothesShopDataSet.AcceptChanges(); // 由于随后要对数据库操作,没有这句话会报错:“违反并发性 UpdateCommand 影响了预期1条记录中的0条”
}private void dataGridView_Kuaidi_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e)
{ if (e.ColumnIndex < 0) { // 行头的ContextMenuStrip设定 e.ContextMenuStrip = this.contextMenuStrip1; dataGridView_Kuaidi.CurrentCell = dataGridView_Kuaidi[0, e.RowIndex]; } }private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
{ int CurrentRowIndex = dataGridView_Kuaidi.CurrentCell.RowIndex; DataGridViewRow row = dataGridView_Kuaidi.Rows[CurrentRowIndex]; dataGridView_Kuaidi.Rows.Remove(row);//防止滚动条滚到不是想要到的地方。
dataGridView_Kuaidi.CurrentCell = dataGridView_Kuaidi[0, CurrentRowIndex]; }private void dataGridView_Kuaidi_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{ if (!e.Row.IsNewRow) { DialogResult response = MessageBox.Show("确定删除该行?", "删除行?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (response == DialogResult.No) e.Cancel = true; } }