Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Readonly cell values after linq binding
posted

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,

                      }

I hope you've got the point.
Thank you in advance

 

Parents
  • 150
    Suggested Answer
    posted

    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;

    yet I could not edit the data in both the UltraGrid (or the Microsoft DataGridView).
    As soon as I made an actual type, I was able to edit in both grids.
    My question is:
    What method does UltraGrid use to determine if a dataset is editable? It appears to be using something other than BindingSource.AllowEdit. I have a situation where I'd like to know beforehand if my data is going to be editable and I'd really like to use the same method used by the UltraGrid so we both get the same answer.
    Thanks,
    Vincent

     

Reply Children