0

On my Winforms app, I have a primary form with a DataGridView bound to a database Entity datasource.

The grid is set up not to allow inserts. Instead I have a button on my form that kicks of a second dialog where the insert takes place (ie. with friendlier ui than is possible with the DataGridView).

The insert is working fine.. query of the underlying table in db shows that the record has been inserted. However, I can't seem to get the DataGridView on the primary form to see the new data just created by the second dialog.

I have read many Stack Overflow q & a's and tried various solutions to get the DataGridView to refresh to show new data.. but nothing works.

This must be a common situation ?? Can someone suggest some VB.NET code that will work ?

Thanks,

Bazza

    Dim qry = From o In mDB.tblFOMTestResults From p In mDB.tblProduct.DefaultIfEmpty _
                                              From c In mDB.tblCalibration _
                Where o.ProductID = p.ID And o.CalibrationID = c.ID _
                Order By o.RunDate, p.ProductName Select _
                o.ID, o.SampleCode, o.RunDate, o.ConditioningDays, o.ConditioningRHAndTemp, _
                o.TestArea, o.EdgeSeal, o.SealedBags, o.FaceSeal, _
                o.MoisturePercentage, o.CalibrationID, o.FYFOMH1, o.FYFOMH2, o.FYFOMH3, _
                o.FYFOMH4, p.ProductName, o.ProductID

    Me.TblFOMTestResultsDataGridView.DataSource = qry
Bazza Formez
  • 179
  • 5
  • 16

2 Answers2

1

Try to bind to the results of the query rather than the query:

dataGridView.Source = query.Execute(MergeOption.AppendOnly);
Jacob Seleznev
  • 8,013
  • 3
  • 24
  • 34
0

After trying a number of things, I finally got this going by following the advice from the following SO answer.. Refresh DataGridView in Windows form

Community
  • 1
  • 1
Bazza Formez
  • 179
  • 5
  • 16