[英]What do I do If the value of a datagridviewcombobox is not in the datagridviewcomboboxcolumn datasource?
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. 现在,抛出了一个异常。我认为在datagridview的dataerror处理程序中,该值不在列表中。
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. 我需要做的是找到一些在填充每个datagridview行时触发的事件,因此我可以检查并查看combobox值是否在combobox数据源中...如果没有,我将其添加。 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. 最好,我希望能够对此检查进行概括,并将其放入从datagridview继承的类中。 This way, I won't have to worry about this problem ever again.
这样,我就不必再担心这个问题了。
Any ideas? 有任何想法吗?
Isaac 以撒
You could try the DataBindingComplete
event. 您可以尝试
DataBindingComplete
事件。 Other options include DataMemberChanged
and DataSourceChanged
. 其他选项包括
DataMemberChanged
和DataSourceChanged
。
It's a bit hard to tell which event would be the most appropriate without seeing some code. 不看一些代码就很难判断哪个事件最合适。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.