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
850
Adding record event
posted

I’m using a binding list to capture data entered into a xamDataGrid. If I edit the top cells directly, I get the usual AddingNew event fired off and everything works as expected.

Using that event, I am able to initialize the new record and populate the other columns.

However if I try to edit those top cells indirectly using the ActiveCell.Value property, it changes the cell value but it doesn’t fire off the AddingNew event on the binding list.

 

I’m using the ActiveCell.Value property because I have an adoring element which is activated when the cell is clicked. The adorning element is a general purpose control so it doesn’t have access to the binding list.

So my question is; how can I get the adding record event to fire off?

 

 

 

  • 27093
    Verified Answer
    posted

    Hello,

     

    I have been looking into issue and usually the RecordAdding/Added events are meant to notify the user when the AddNewRecord UI is used. Like most events it is assumed that it needn’t be triggered from code made changes, since the developer knows about them and can react accordingly, without the use of a notifying mechanism like the events.

     

    That being said, I did some research of my own and I was able to trick the XamDataGrid to raise its event after a code manipulation. Instead of setting the ActiveCell’s Value I used the following code:

     

    //xamDataGrid1.ActiveCell.Value = "indirect test";

    xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);

    CellValuePresenter cell = CellValuePresenter.FromCell(xamDataGrid1.ActiveCell);           

    (cell.Editor as XamTextEditor).Text = "indirect test";

     

    Which will simulate the UI text input and will trigger the value binding and as a result you the xamDataGrid1_RecordAdding event will be raised and the other default values will be filled.

     

    Please let me know if you require any further assistance on the matter.