111,126
社区成员
发帖
与我相关
我的任务
分享
public Form1()
{
InitializeComponent();
dataGridView1.AllowUserToDeleteRows = false;
}
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
MessageBox.Show("Primary key is " + row.Cells["PrimaryKey"].Value);
dataGridView1.Rows.Remove(row);
}
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行
DialogResult result = MessageBox.Show("是否要修改当前行中单元格的内容?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (this.dataGridView1.SelectedRows.Count > 0)
{
if (result == DialogResult.Yes)
{
//修改当前行单元格的内容
}
}
}