Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to force DataGridView to re-populate its rows using IQueryable<TEntity>
    primarykey
    data
    text
    <pre><code>BlaEntities TestContext = new BlaEntities(); IQueryable&lt;TestEntity&gt; Entities = TestContext.TestEntity; TestDataGridView.DataSource = Entities; </code></pre> <p>When I assign Entities to TestDataGridView's DataSource directly; I don't have to do anything to reflect my changes to the grid.</p> <pre><code>TestEntity entity = Entities.First(); entity.Title = "What up!?"; </code></pre> <p>This is more than enough to see the change in the TestDataGridView. One exception I encountered was that if I add another row to the TestContext using <code>TestContext.AddToTestEntity(...)</code> , it doesn't show up in the grid (contrary to deleting it) but I got it working using the BindingSource's Add method.</p> <pre><code>BindingSource source = new BindingSource{DataSource = Entities}; TestDataGridView.DataSource = source; source.Add(CreateNewTestEntity()); </code></pre> <p>Now the only obstacle left in my way is this: If I use filtering - like <code>TestContext.Where(t =&gt; t.Active)</code> - use it as DataSource to my grid, then change the first record's Active property to false, how do I refresh/reload the grid to reflect this without creating another instance of BlaEntities?</p> <pre><code>IQueryable&lt;TestEntity&gt; FilteredEntities = TestContext.TestEntity.Where(t =&gt; t.Active); TestDataGridView.DataSource = FilteredEntities; TestEntity temp = FilteredEntities.First(); temp.Active = false; </code></pre> <p>I see it is not active anymore in grid but since the grid should show only the active records, how can I remove it from the grid without removing it from the source?</p> <ul> <li>When I iterate over <code>FilteredEntities</code>, I can see that the <code>temp</code> isn't there anymore but I still can see and edit it in the grid. So what I need is something forces grid to iterate its DataSource (which is FilteredEntities) as well and populate itself again</li> <li>I tried calling <code>TestContext</code>'s <code>Refresh</code> method and <code>BindingSource</code>'s reset methods.</li> <li>I tried changing <code>TestDataGrid.DataSource</code> to <code>null</code>, then changing it back to <code>FilteredEntities</code> hoping to re-populate the rows, didn't work either.</li> <li>It works if I save my changes using <code>TestContext.SaveChanges()</code> and use another instance of <code>BlaEntities</code> like <code>TestDataGridView.DataSource = new BlaEntities().TestEntity.Where(t =&gt; t.Active)</code> but I need to use my current instance.</li> </ul> <p>So the question is, how can I make the TestGridView to reload its contents using FilteredEntities. Any advice would be greatly appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload