gpt4 book ai didi

c# - 如何暂停更新有界 DataGridView 中当前正在编辑的单元格?

转载 作者:行者123 更新时间:2023-11-30 22:37:29 24 4
gpt4 key购买 nike

我有一个绑定(bind)到集合的 DataGridView,它经常更改(不是集合本身,而是对象的属性)。当我开始编辑单元格时,它会迅速替换为来自 PropertyChanged 事件的新值。无论如何要“暂停”当前正在编辑的单元格进行更新。

最佳答案

你应该能够通过添加一个 BindingSource 来实现你想要的。

bindingSource1.DataSource = yourdatasource;
dataGridView1.DataSource = bindingSource1;

然后,在数据 GridView 的 CellBeginEdit 和 CellEndEdit 事件中,您可以更改绑定(bind)源的 RaiseListChangedEvents 属性:

void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
bindingSource1.RaiseListChangedEvents = true;
}

void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
bindingSource1.RaiseListChangedEvents = false;
}

我用一个后台 worker 测试了这个,里面有一个 sleep 由一个按钮启动,然后更新绑定(bind)列表。我按下按钮然后编辑了一个单元格,在计时器到期后,我对单元格的更改仍然保留。

当我没有开始编辑单元格时,对列表的更改已更改。


需要注意的是,这是针对整个绑定(bind)源,而不是特定单元格。

关于c# - 如何暂停更新有界 DataGridView 中当前正在编辑的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6522211/

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