访问绑定源列值
如何使用代码更新绑定源中的列值?
我正在尝试类似的操作:
CustomersBindingSource.AddNew();
CustomersBindingSource.Current["CustomerID"] = Guid.NewGuid();
此代码当前错误指出:“无法将 [] 索引应用到‘object’类型的表达式”。
非常感谢任何重写此内容的帮助!
How can I update a column value in a binding source with code?
I am trying for something similar to this:
CustomersBindingSource.AddNew();
CustomersBindingSource.Current["CustomerID"] = Guid.NewGuid();
This code currently errors stating: "Cannot apply indexing with [] to an expression of type 'object'".
Any help re-writing this is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BindingSource 的 Current 属性在以下环境中非常通用它返回什么:类型对象。对象没有定义索引器,因此您的 [] 不起作用。您需要做的是将 Current 属性转换为它真正的(更具体的)类型。
例如,如果 Current 实际上是 DataRowView,您可以编写:
希望这有帮助,
本
BindingSource's Current property is very generic in what it returns: type object. Object doesn't define an indexer so your [] doesn't work. What you need to do is cast the Current property to the (more-specific) type of what it really is.
For example, if Current is really a DataRowView, you could write:
Hope this helps,
Ben