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
229
Update grid after editing
posted

Hi,

I have the following problem. I present the user a grid. This grid is a usercontrol with an UltraGrid and a BindingNavigator.

It is connect with the data like this:

this.oDataAdapter = new SqlDataAdapter();
this.oDataAdapter.SelectCommand = oCommand;
this.oDataAdapter.Fill(this.oTableGrid);
this.oBindingSource = new BindingSource();
this.oBindingSource.DataSource = this.oTableGrid;
this.ultraGrid1.DataSource = this.oBindingSource;
this.bindingNavigator1.BindingSource = this.oBindingSource;

Now when a row needs editing, the user doubleclicks and a form is generated ( my app is datadriven ).  For this form the data is first reread from the database.  I cannot share the BindingSource of the grid, as often a view is displayed and not every view is editable.
After editing, the modified data is written to the database, so I need to reread the data for the grid to be updated. Like this:

this.oTableGrid.Clear();
t
his.oDataAdapter.Fill(this.oTableGrid);

This works, but gives me the grid in the start position. A grouping is still active, but after rereading the data, the data of the previous expanded group needs to be expanded again.

Is there a way to restore the layout like how it was before editing? I have tried to do it with saving and loading a layout file

this.ultraGrid1.DisplayLayout.Save(Filename);

but this does not work in for me in this situation.
Another thing I have tried without success is this:

this.ultraGrid1.ActiveRow.Refresh(RefreshRow.ReloadData);
this.ultraGrid1.ActiveRow.Refresh(RefreshRow.RefreshDisplay);

Can anyone give me a hint how to solve this problem?

kind regards,

 

Erik Visser

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi Erik,

    The grid layout does not (and cannot) include any row-level properties or state information. The grid cannot possibly know that the row it had in the original set of data is the same as some new row (which is a completely new object) in a new table of data.

    So if you want to maintain the scroll position of the grid, you will have to store some key information about the row at the top of the grid before you clear the table, then find the new row with that same key info and scroll to it afterward.

    To get or set the row, you can use grid.ActiveRowScrollRegion.FirstRow.

     

Children