private void CveDataGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { SQLiteCommandBuilder scb = new SQLiteCommandBuilder(mAdapter); mAdapter.InsertCommand = scb.GetInsertCommand(); mAdapter.Update(ds, t_name); CveDataGridView.ClearSelection(); }
private void CveDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0) { CveDataGridView.ClearSelection(); CveDataGridView.Rows[e.RowIndex].Selected = true; } DataGridcontextMenuStrip.Show(MousePosition.X, MousePosition.Y); } }
private void CveDataGridView_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.F5: SelectAll(); break; case Keys.Delete: DialogResult result; result = MessageBox.Show("确定要删除!" + "ID=" + CveDataGridView.Rows[CveDataGridView.CurrentRow.Index].Cells["ID"].Value, "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result != DialogResult.OK) { CveDataGridView.ClearSelection(); } else { try { this.ds.AcceptChanges(); SQLiteCommandBuilder scb = new SQLiteCommandBuilder(this.mAdapter); ds.Tables[0].Rows[CveDataGridView.CurrentRow.Index].Delete(); // dt.Rows[CveDataGridView.CurrentRow.Index].Delete(); this.mAdapter.DeleteCommand = scb.GetDeleteCommand(); this.mAdapter.Update(ds, this.t_name); CveDataGridView.ClearSelection(); } catch (Exception) { } } break; } }