Datagridview、绑定源以及无效操作错误
foreach (Listing s in fx)
{
ListingBindingSource.Add(s);
}
我的代码中的这会导致以下错误:
无效操作错误:由于对象的当前状态,操作无效。
现在我检查了,我正在主线程上运行它。
而且,它之前一直在工作。最近发生的变化是我将列表成员(其中两个)从 int 更改为 string。我想如果我删除 Listbindingsource 并重新制作它,它会自动改变这一点。但看来我必须做点别的事情。任何人都可以在这里阐明一些情况。 ListBindsource 是 datagridview 的数据源。 谢谢
***解决方案**** **
public Form1()
{
InitializeComponent(); Listing s1 = new Listing();
ListingBindingSource.Add(s1);
}
出于某种原因添加了它。当由于某种原因创建表单时,null 被传递到绑定源中。为什么,我不知道。
一些附加信息:
如果我删除绑定源作为 gridview 的数据源,错误就会消失
foreach (Listing s in fx)
{
ListingBindingSource.Add(s);
}
This in my code causes the following error:
Invalid operation error: Operation is not valid due to the current state of the object.
Now i checked, I am running this on the main thread.
Also, it was working before. What changed recently is i changed Listing members, two of them, from int to string. I thought if i delete Listbindingsource and remake it, it would automatically change that. But it seems i have to do something else. Can anyone shed some light here.
ListBindsource is the datasource to a datagridview.
thanks
***SOLUTION******
public Form1()
{
InitializeComponent(); Listing s1 = new Listing();
ListingBindingSource.Add(s1);
}
for some reason this added it. When the form was created for some reason null was being passed into the bindingsource. why, i don't know.
Some additional info:
If i remove the bindingsource as a datasource of the gridview, the error vanishes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“Add 方法引用调用到底层列表的 Add 方法。
内部列表必须包含同质类型。如果尚未设置 DataSource 属性,则添加到列表的第一个对象将定义列表的类型。
"The Add method refers the call to the underlying list's Add method.
The internal list must contain homogenous types. If the DataSource property has not already been set, then the first object added to the list defines the type for the list"