gpt4 book ai didi

.net - 当用户取消添加过程时,如何删除正在添加的DataGridView行?

转载 作者:行者123 更新时间:2023-12-05 09:00:35 24 4
gpt4 key购买 nike

我有一个数据绑定(bind) DataGridView。当添加新行并且用户按下 Esc 我想删除整行。我该怎么做?

最佳答案

其实很简单

private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)27)
{
if (dataGridView1.Rows.Count > 0)
{
dataGridView1.Rows.RemoveAt(dataGridView1.Rows.Count - 1);
MessageBox.Show("Last row deleted!");
}
e.Handled = true;
}
}

但请记住:

Rows cannot be programmatically removed unless the DataGridView is data-bound to an IBindingList that supports change notification and allows deletion

关于.net - 当用户取消添加过程时,如何删除正在添加的DataGridView行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/207901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com