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
455
Modifying ActiveCell value while in BeforeCellUpdate
posted

Hi there,

I am trying to find a good way to modify some values in the row I am working on.

The situation is as follows:

I have a grid with a startdate, enddate and duration. On doubleclicking and editting for example the startdate the BeforeCellUpdate is called when leaving the cell.

In the BeforeCellUpdate there are a few checks to see if there are overlaps, etc. and finally I want to set the cells on the selected row so I do the following:

grid.ActiveCell.Row.Cells["ColumnName"].Value = e.NewValue;

Now when editting the cell I get the following exception on this row:

InvalidOperationException

Value property can not be assigned while BeforeCellUpdate event is in progress

I have been thinking of globally setting a variable and updating the values in the AfterCellUpdate but isn't there a better way to resolve this?

Thank in advance!

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    It's a little odd to update other cells in BeforeCellUpdate, because the update in the current cell hasn't completed, yet. I recommend using AfterCellUpdate, which fires after the current update has been committed to the underlying data source.

    Having said that, I'm not sure why the grid is not allowing you to update the Value of other cells. I can understand why it doesn't let you change the Value of the cell currently in the process of being updated, but I don't see why other cells would cause a problem. I might just be missing something, so I will check it out and get back to.

    But in any case, I still think it makes more sense to use AfterCellUpdate because the update of the current cell could fail and then you will have updated the other cells in the row erroneously.

     

Children