This is a migrated thread and some comments may be shown as answers.

Refilling a RadGridView using Entitiy Framework instead of Dataset

3 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 17 Dec 2011, 12:20 PM

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.

3 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
answered on 17 Dec 2011, 06:22 PM
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.
0
Thomas
Top achievements
Rank 1
answered on 18 Dec 2011, 03:41 PM
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()".
0
Julian Benkov
Telerik team
answered on 21 Dec 2011, 12:08 PM
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.
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Thomas
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or