为什么网格变成只读?如何避免只读网格问题?
我有一个要绑定的 DevExpress xtraGrid。当我尝试绑定时,编译器给出错误,指出 gridView 数据源是只读的。我尝试了以下方法,我的代码是
NorthwindDataContext db = new NorthwindDataContext();
var r = from p in db.Orders
select p;
var r2 = from p in db.Order_Details
select p;
gridView1.DataSource = r;
gridView2.DataSource = r2;
我收到以下错误: 属性或索引器'DevExpress.XtraGrid.Views.Base.BaseView.DataSource'无法分配给--它是只读的
我检查了gridView上的列属性,它不是只读的。为什么我会收到此错误?实际上我的网格是空的,我要将它绑定到数据库。
I have a DevExpress xtraGrid which I want to bind. When I try to bind, the compiler gives an error that the gridView datasource is readonly. I tried the below approach, my code is
NorthwindDataContext db = new NorthwindDataContext();
var r = from p in db.Orders
select p;
var r2 = from p in db.Order_Details
select p;
gridView1.DataSource = r;
gridView2.DataSource = r2;
I get the following error:
Property or indexer 'DevExpress.XtraGrid.Views.Base.BaseView.DataSource' cannot be assigned to -- it is read only
I checked my column property of on the gridView and It is not read only. Why I am getting this error? Actually my grid is empty, I am going to bind it to a database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置控制
GridView
的GridControl
的DataSource
,而不是GridView
本身。来自 DevExpress 的站点:如何:在运行时将控件绑定到数据库
You need to set the
DataSource
of theGridControl
that controls yourGridView
, not of theGridView
itself.From DevExpress's site: How to: Bind a Control to a Database at Runtime
默认情况下,XtraGrid 将识别您的关系并为子表创建克隆视图。如果您想更改视图选项(隐藏列、更改格式等...),您可以定义自己的 GridView,但这需要您设置 GridControl 的 LevelTree 属性。
By default, the XtraGrid will recognize your relationships and create cloned views for the child tables. You can define your own GridViews if you want to change view options (hide columns, change formatting etc...), but this will require you to set the GridControl's LevelTree property.