4

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.

dsolimano
  • 8,870
  • 3
  • 48
  • 63
shamim
  • 6,640
  • 20
  • 85
  • 151

2 Answers2

7

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

dsolimano
  • 8,870
  • 3
  • 48
  • 63
  • thanks for help.my grid need to show Master detail relationship.Suppose i use northwind database.I have three table customer,Order,Order_details.I want to show this relation table's values in my grid.How to – shamim Nov 12 '10 at 16:37
  • @Shamim, DevExpress supports master-detail tables, documentation is at http://documentation.devexpress.com/#WindowsForms/CustomDocument3473. You should read that and post specific questions if you encounter any difficulties. – dsolimano Nov 12 '10 at 18:24
0

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.

Brendon
  • 41
  • 1