shamim
shamim

Reputation: 6768

Why grid become readonly? How to avoide readonly grid problem?

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.

Upvotes: 4

Views: 6046

Answers (2)

Brendon
Brendon

Reputation: 41

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.

Upvotes: 0

dsolimano
dsolimano

Reputation: 8996

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

Upvotes: 7

Related Questions