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
235
Updating UltraWinGrid Using Separate Data Entry Form
posted

I am attempting to update an UltraWinGrid control, using an SQLServer database and Entity Framework. When the user double clicks the grid, a new "Editing" form is opened with text edit fields showing all of the columns on the grid for the selected record. All of this works correctly. The form allows editing and deleting of the selected record. When the record is changed through editing using the separate form, the changes are immediately reflected in the grid on the original form. The same is true of deleting a record; the deleted record is instantly removed from the grid.

But when I attempt to add a new record through the "Editing" form, the new record does not appear in the grid after saving and exiting the editing form. The record, however, is saved to the database the instant the "SaveChanges" command is executed. If the program, is stopped and then restarted, the new record appears correctly in the grid. I have tried the following to force the update:

this.c_Chemical_Prospects__BindingSource.ResetBindings(false);

this.ultraGrid1.Rows.Refresh(RefreshRow.ReloadData);

The code to save the new record is as follows:

lblStatus.Text =

"Prospect Saved";

DisableControls();

prospectDetail =

new C_Chemical_Prospects__();

 

this.PutProspectData(prospectDetail);

 

ChemicalEntity.TNChem.AddToC_Chemical_Prospects__(prospectDetail);

 

try

{

 

ChemicalEntity.TNChem.SaveChanges();

 

ChemicalEntity.TNChem.Refresh(RefreshMode.StoreWins, prospectDetail);

}

 

catch (Exception ex)

{

 

MessageBox.Show(ex.Message, ex.GetType().ToString());

}

I don't know what else to try.

  • 469350
    Suggested Answer
    Offline posted

    Hi,

    It's hard to guess why this isn't working without knowing what you are doing. I assume you are binding the control on the editing form to the same data source that the grid is bound to and that somehow you are setting it up so that the grid and the other controls have the same BindingContext.

    If the grid is not showing a new record which has been added to it's DataSource, then it means that the DataSource is not sending a notification about the new row.

    Since your grid is receiving notifications of data changes and deletes, this seems pretty odd that it's not getting a notification for adds. I'm not familiar with the EntityFramework, but maybe there is something you have to do to get it to send these kinds of notifications? Does it work if you simply add a row to the data source in code - like in a button on the same form with the grid?

    You shouldn't have to do this, but you might want to try calling grid.Rows.Refresh(ReloadData) after the row has been added. If the new row exists in the data source, refreshing the grid rows should cause the grid to display it.