如果 datagridviewcombobox 的值不在 datagridviewcomboboxcolumn 数据源中,我该怎么办?

发布于 2024-10-14 20:53:15 字数 357 浏览 5 评论 0原文

我遇到的情况是下拉列表必须仅包含“活动”对象。然而,这并不意味着当前组合框值将在列表中(它是在对象处于活动状态时选择的,但不再处于活动状态)。

现在的情况是,抛出了一个异常。我认为在 datagridview 的 dataerror 处理程序中,它表示该值不在列表中。

我需要做的是找到填充每个 datagridview 行时触发的一些事件,这样我就可以检查并查看组合框值是否在组合框数据源中...如果没有,我会添加它。这是我能看到的唯一解决方案。但问题是,我应该使用哪个事件处理程序?

最好,我希望能够概括此检查并将其放入从 datagridview 继承的类中。这样我就不用再担心这个问题了。

有什么想法吗?

艾萨克

I've got a situation where the drop down list has to contain only 'active' objects. However this doesn't mean the current combobox value will be in the list (it was selected at a time that object was active, but is not active anymore).

As things are now, there's an exception thrown.. I think in the dataerror handler of the datagridview, that says the value is not in the list.

What I need to do is find some event that is fired when each datagridview row is populated, so I can check and see if the combobox value is in the combobox datasource... if not, I'd add it. That's the only solution I can see. But the question is, which event handler should I use for this?

Preferably, I'd like to be able to generalize this check and put it in a class that inherits from datagridview. This way, I won't have to worry about this problem ever again.

Any ideas?

Isaac

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

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

发布评论

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

评论(1

护你周全 2024-10-21 20:53:15

您可以尝试 DataBindingComplete 事件。其他选项包括 DataMemberChangedDataSourceChanged

如果不看一些代码,很难判断哪个事件最合适。

You could try the DataBindingComplete event. Other options include DataMemberChanged and DataSourceChanged.

It's a bit hard to tell which event would be the most appropriate without seeing some code.

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