Hi, I have a Grid with DataSource linked to result from LINQ2SQL stmt. LINQ2SQL returns 4 columns ( from table A ) out of 8 more columns comes from 2 different tables ( table A and B joined together ). Grid is using only those 4 columns ( from table A ) and rest of them are not visible to view ( comes only from table A ). I have created grid based on table A. I have a problem because when I am trying to edit any of existing ( retrieved ) data from LINQ2SQL stmt used by Grid I simply can't do this. I can select cell but I can not delete/edit or add any character inside any cell. I am adding a new row to the grid by: this.testGrid.DisplayLayout.Bands[0].Override.AllowAddNew = AllowAddNew.TemplateOnTop; I got an error message 'Row insertion not supported by this data source' and I can't even get focus to any cell on the grid. What I am doing wrong ? Any suggestions how to allow user to add new row ? Regards Piotrek my example : DATABASE: --------- tablea: column_1a column_2a column_3a column_4a column_5a column_6a column_7a column_8a tableb: column_1b column_2b column_3b column_4b C# CODE: -------- ( on_Load Form event ... ) var query_test = from a in dc_test.tablea from b in dc_test.tableb where ( a.column_1a == b.column_1b & b.column_2b == '123' ) select new { a.column_1a, a.column_4a, a.column_5a, a.column_6a, }; this.testGrid.DisplayLayout.Bands[0].Override.AllowAddNew = AllowAddNew.TemplateOnTop; this.testGrid.DataSource = query_test; this.testGrid.DataBind(); this.testGrid.Refresh();
I've seen situations like this before. I think typically, when you use a SQL query that joins two tables, the table is returned to you read-only by default. I'm not sure if there is any way to make such a join updatable or how that would work if it was. You might be better off posting your question on a more general DotNet programming or Microsoft forum - since this is really not related to the WinGrid.
Hi again,
I hale discovered that I got an terror with editing and adding new row if I am using SELECT NEW stmt in LIN2SQL query.
var query_test = from a in dc_test.tablea from b in dc_test.tableb where ( a.column_1a == b.column_1b & b.column_2b == '123' ) select new { a.column_1a, a.column_4a, a.column_5a, a.column_6a, }; this.testGrid.DisplayLayout.Bands[0].Override.AllowAddNew = AllowAddNew.TemplateOnTop; this.testGrid.DataSource = query_test; this.testGrid.DataBind(); this.testGrid.Refresh();
When I will use section of all rows ( not only several rows ) everything is Ok and I can edit/add or delete rows/cells.
var query_test = from a in dc_test.tablea from b in dc_test.tableb where ( a.column_1a == b.column_1b & b.column_2b == '123' ) select a; this.testGrid.DisplayLayout.Bands[0].Override.AllowAddNew = AllowAddNew.TemplateOnTop; this.testGrid.DataSource = query_test; this.testGrid.DataBind(); this.testGrid.Refresh();
Any idea what I am doing wrong ? In my opinion I have to do something with DataSource but I have no idea what.
Regards
Piotrek