【问题标题】:Control is updated but no event is triggered控件已更新,但未触发任何事件
【发布时间】:2014-12-15 10:13:10
【问题描述】:

我有一个DataGridView,它引用了应用程序图上的对象。出于某种原因,当我通过拖放在图表上添加曲线时,单元格不会更新。当我悬停数据DataGridView 的单元格时,会执行一些神秘的代码。我在DataGridView 触发的每个事件上都设置了一个断点,但我找不到任何东西。如果我一步一步调试,调用堆栈会显示External code。以下是我关注的事件:

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
private void dataGridView1_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e)
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)

DataSource 设置好了,这会是罪魁祸首吗?

如何进行更多调查?

【问题讨论】:

  • @t3chb0t 不不,这不是我想做的,我会尝试重新制定
  • 你设置为DataGridView的DataSource的对象是什么类型的?
  • @Junaith 这是BindingList
  • BindingList 元素的类型是什么?它是否正确实现了 INotifyPropertyChanged?

标签: c# datagridview


【解决方案1】:

BindingList 元素类型必须实现INotifyPropertyChanged 接口才能触发ListChanged 事件,这反过来又更新DataGridView

来自 MSDN: 仅当列表项类型实现 INotifyPropertyChanged 接口时,才会引发有关项值更改的 ListChanged 通知。

在您的自定义类型中实现INotifyPropertyChanged 接口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多