如果 datagridviewcombobox 的值不在 datagridviewcomboboxcolumn 数据源中,我该怎么办?
我遇到的情况是下拉列表必须仅包含“活动”对象。然而,这并不意味着当前组合框值将在列表中(它是在对象处于活动状态时选择的,但不再处于活动状态)。
现在的情况是,抛出了一个异常。我认为在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试
DataBindingComplete
事件。其他选项包括DataMemberChanged
和DataSourceChanged
。如果不看一些代码,很难判断哪个事件最合适。
You could try the
DataBindingComplete
event. Other options includeDataMemberChanged
andDataSourceChanged
.It's a bit hard to tell which event would be the most appropriate without seeing some code.