0
votes

I have created a WPF desktop project with a tab control. On each tab are multiple DataGrid controls. I want to be able to edit some of them and add new rows, but all of them are read-only. I checked and the datagrid IsReadOnly property is false, but all of the columns' IsReadOnly properties are true. I tried setting the columns' IsReadOnly properties to false in debug mode while the program is paused, but they stay set to true. I suspect something in the data binding is forcing the columns to read-only, but I don't know what. I am binding to Entity Framework 6.0 objects. I created a new test project with a DataGrid using the same data objects and that DataGrid can be edited. I don't understand what is different. There's a lot of code involved and I'm not sure what to post here that would be helpful. Does anyone have an idea why none of the DataGrids in the project cannot be edited?

Edit: Here's some of the app.config file. The .NET Framework is set to 4.5

  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
1
can you show your bindings?thumbmunkeys
Please show us some code.BendEg
Below is some code with my proposed answer. Thanks for trying to help.Steve Gaines

1 Answers

0
votes

I think I found the answer to this problem. Below is my data binding. I am creating an anonymous object in the select clause. Apparently, the DataGrid doesn't know how to edit that. If I change it to .Select(o => o) then it is editable. I guess I can define some objects for the records I want to edit, or just use the EF class objects.

var oQuery = oContext.EntityOwners
.Where(o => o.EntityEIN == sEIN)
.Select(o => new { Delete = "Delete", OwnerEIN = o.OwnerEIN, X_pound_X_Shares = o.Shares, _EIN = o.OwnerEIN });