在winform中的焦点事件期间根据绑定值更新值

发布于 2024-10-27 20:39:50 字数 664 浏览 1 评论 0原文

我有一个绑定到 LLBLGen 实体的 WinForms 表单(尽管我相信这个问题不是特定于这个绑定源的,我提到它只是为了以防万一)。我的目标似乎很简单:根据其他字段的计算更新表单上的另一个字段。

我的问题是,我想重用表单上其他地方使用的相同业务逻辑来执行此计算,因此我将绑定实体传递到业务逻辑层,以便可以对其进行处理。

我觉得奇怪的是,我在焦点链中找不到位置(请参阅:http://msdn.microsoft.com/en-us/library/system.windows.forms.control.enter.aspx ),我可以在其中使用绑定实体更新表格。计算执行得很好,但使用的是更新前的值。

我过去曾通过从 .text 中获取值、验证它们是否可用并从那里开始解决这个问题。我还使用“更新”按钮解决了这个问题:即使我在编辑值时立即单击,单击事件也可以访问更新的值。

不过,我似乎遗漏了一些明显的东西:事件链中的某个地方应该更新绑定值,并且我应该能够在那里运行我的计算。

我的核心问题:我应该使用什么事件来访问 WinForms 中更新的绑定元素?

I have a WinForms form bound to a LLBLGen entity (although I believe this problem to not be specific to this binding source, I mention it just in case). My goal seems pretty simple: update another field on the form based on a calculation for the other fields.

My problem is that I want to reuse the same business logic that is used elsewhere on the form to do this computation and thus I am passing the bound entity to the business logic layer so it can be processed.

What I find strange is that I can't find a place in the focus chain (see: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.enter.aspx ) where I can use the bound entity in an updated form. The calculation is performed fine, but with the pre-update values.

I have worked around this in the past by grabbing values from .text, validating them as usable and going from there. I have also worked around it with "update" buttons: the click event can access the updated value, even if I was clicking immediately from editing a value.

Still, it seems like I'm missing something obvious: somewhere in the event chain the bound value should be updated and I should be able to run my calculation there.

My core question: what event should I be using to get access to the updated bound element in WinForms?

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

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

发布评论

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

评论(1

失去的东西太少 2024-11-03 20:39:51

考虑到我关心的是获取绑定数据更改,我停止计算 UI 事件并切换到监听相关实体上的 PropertyChanged() 事件。这绕过了问题并且工作得很好......并且可能是我首先应该做的。)

我暂时将其保留为未答复;也许有人仍然对焦点事件链的基本问题有答案。我尚未使用其他绑定源测试此解决方案,但由于 INotifyPropertyChanged 是数据绑定的基础,我怀疑该技术也适用于其他数据源。

Considering that my concern was with getting at the bound data changes, I stopped calculating on UI events and switched to listening to the PropertyChanged() event on the entity in question. This bypassed the problem and is working great... and is probably what I should have been doing in the first place.)

I will leave this as unanswered for now; perhaps someone still has an answer for the base question in terms of the focus event chain. I haven't tested this solution with other binding sources, but as INotifyPropertyChanged is the foundation of databinding I suspect the technique will work with other data sources.

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