为什么网格变成只读?如何避免只读网格问题?

发布于 2024-10-01 14:29:46 字数 555 浏览 3 评论 0原文

我有一个要绑定的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温馨耳语 2024-10-08 14:29:46

您需要设置控制 GridViewGridControlDataSource,而不是 GridView 本身。

来自 DevExpress 的站点:如何:在运行时将控件绑定到数据库

You need to set the DataSource of the GridControl that controls your GridView, not of the GridView itself.

From DevExpress's site: How to: Bind a Control to a Database at Runtime

橘虞初梦 2024-10-08 14:29:46

默认情况下,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文