Refilling a RadGridView using Entitiy Framework instead of Dataset

4 posts, 0 answers
  1. Thomas
    Thomas avatar
    34 posts
    Member since:
    Nov 2011

    Posted 17 Dec 2011 Link to this post

    Hello,

     

    I'm looking for the Entity Framework equivalent of dataset's tableAdapter.Fill/tableAdapter.FillByBy.

    Because they were reusable to refill a GridView (Windforms), possibly using a different 'where clause'.

    The only way I know to fill/refill the GridView from DB now using EF with different parameters:

    this.myBindingSource.DataSource =  myNewSelectQueryObject;

    the 'first fill' with this works fine, but the second one will cause the DataSource et the GirdView to be impossible to edit. (Although the BindingSource the GridView are NOT 'readonly'.) a,d EF.Refresh() doesn't seem to update records that could be in the DB but are not present in the 'EF'.

     

    Thank you for your help.

  2. Thomas
    Thomas avatar
    34 posts
    Member since:
    Nov 2011

    Posted 17 Dec 2011 Link to this post

    Here is some progress but I'm not satisfied yet :
    Refill(){
    this.myDataEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, this.myDataEntities.myEntity);
    this.myBindingSource.DataSource = myNewObjectQuery<...>;
    this.myRadGridView.DataSource = this.myBindingSource.DataSource;
    }

    optionnally with :
    this.myRadGridView.MasterTemplate.DataSource = this.myBindingSource.DataSource;
    not sure if this is usefull.

    The RadGridView is not 'apparently readonly' anymore.

    But then I want to add a record through my BindingSource:
    this.myBindingSource.AddNew();
    It does not appear in my RadGridView.
    While I still can add a record and save it by clicking on using the 'Click here to add a new row' tool from the RadGridView.

    So there's some mismatch between the BindingSource and the grid.
  3. Thomas
    Thomas avatar
    34 posts
    Member since:
    Nov 2011

    Posted 18 Dec 2011 Link to this post

    If seems that the solution was to make something like this:

    Refill(){
        this.myDataEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, this.myDataEntities.myEntity);
        this.myBindingSource = new BindingSource();
        this.myBindingSource.DataSource = myNewObjectQuery<...>;
        this.myRadGridView.DataSource = this.myBindingSource;
    }

    The important difference is the "new Bindingsource()".
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 21 Dec 2011 Link to this post

    Hi Thomas,

    You can also use the ToList() method to convert your query result to IList and bind it to RadGridView to have support of edit operations. Another important thing is that you should avoid using anonymouse types in LINQ query. The binding in this situation will show read-only data. More information about LINQ expression binding you can find in this blogpost.

    I hope this helps.

    Best wishes,
    Julian Benkov
    the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top