Hello!
I have a question related to binding a linq query result set to a datagrid.
My problem is: after binding linq result set to ultragrid I cannot modify the cell values. All of the cells are read only. As I saw, this happens only when I use Anonymus types.
Lets take an example:
var query = from p in db.Employees // This works (I can edit the cells)
Select p;
var query = from p in db.Employees // This also works but I can not edit the cells in ultragrid
Select new
{
FirstName = p.FirstName;
LastName = p.LastName,
}
Hi,
It's been a long time since you've asked this question. However, I'm having the same problem and I've only got bad news.
The second query uses anonymous types and this is why you cannot edit. If you were to create a class:
public MyClass
{ public String FirstName { get; set; } public String LastName { get; set; }}
then, use "select new MyClass { FirstName = p.FirstName, LastName=p.LastName} in your query, you should be able to edit in the grid.
The "bad news" about this is that although the user can now edit the values, the updates are not made to the object from which they came. In other words, if this was a Person class that existed in an Entity Framework model, the changes are not applied to the Person object (and therefore, not saved in the database), they are applied to the unrelated MyClass object we created for the query.
----------
Like I said, I'm having the same problem and that's how I fixed it, *but*, before I fixed it, the method "BindingSource.AllowEdit" returned true *and* I had every property set in the UltraGrid to enable editing:
ultraGrid1.DisplayLayout.Override.AllowUpdate = DefaultableBoolean.True; ultraGrid1.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.True;
Hi Vincent,
The grid calls into the BindingManager in DotNet to get the data structure. This returns a list of PropertyDescriptors and it is these PropertyDescriptors that tell the grid whether the fields are editable or not.