IBindingList 更改通知

发布于 2024-12-11 13:40:36 字数 450 浏览 1 评论 0原文

我正在尝试创建一个程序(简单的网格 - 具有专门的输出)来显示来自 IBindingList 数据源的数据。我可以很好地显示数据,但我也希望能够让用户编辑数据,例如在与网格分离的文本框中编辑数据。我的问题是,我不清楚如何完成两个元素(我的网格和可编辑文本框)之间的数据“自动”更新。

我相信,列表的 ListChanged 事件会告诉我列表本身何时发生更改,但我需要网格知道列表中的实际数据何时发生更改。当网格外部发生更改时,我偶然发现的唯一告诉我的是挂钩 BindingManagerBase.Bindings[0].Parse 事件。并不是说用户会这样做,但如果用户已经建立了多个都绑定到同一字段的文本框,我想我必须循环遍历每个 BindingManagerBase.Binding 条目并挂钩它?

我认为我没有正确执行此操作,并且有一种更通用的方法可以实现此目的。我非常感谢任何更熟悉我想要完成的任务的人的指导。

提前致谢, -马特

I am trying to create a program (simple grid - with specialized output) that displays data from an IBindingList data source. I can display the data just fine, but I also want to be able to let the user edit the data in, say in a TextBox that is separate from the grid. My problem is that I am unclear as to how to accomplish the "automatic" updating of the data between the two elements (my grid and the editable textbox).

The list's ListChanged event, I believe, will tell me when the list itself has changed, but I need the grid to know when the actual data in the list has changed. The only thing I have stumbled upon to tell me when a change external to the grid has occurred is to hook onto the BindingManagerBase.Bindings[0].Parse event. Not that a user would do this, but if the user has established several textboxes that are all bound to the same field, I think I would have to loop through each BindingManagerBase.Binding entry and hook it?

I am presuming I am not doing this correctly, and there is a more generalized way to accomplish this. I would GREATLY appreciate some direction from anyone who is more familiar with what I am attempting to accomplish.

Thanks in advance,
-Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖风昔人 2024-12-18 13:40:36

查看 INotifyPropertyChanged。在存储在 BindingList 中的类上实现它,以便在项的属性发生更改时通知所述 BindingList。

如果您自己实现了 IBindingList,则需要做更多的工作来连接列表中每个项目的事件,但提供的 BindingList 将自动获取这些事件。

Have a look at at INotifyPropertyChanged. Implement it on the class that is stored in your BindingList to notify said BindingList when properties on an item change.

If you've implemented IBindingList yourself you'll need to do a little more work to hook up to the events for each item in your list, but the provided BindingList will pick up on these events automatically.

肤浅与狂妄 2024-12-18 13:40:36

您还可以使用通用 BindingList 并使用 ResetItem 通知编辑

You could also use the generic BindingList and notify the edit using ResetItem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文