Hello,
how can I immediately update the bound value of a field? When I typ in a letter, I want to see change in the bound value, instead of having to lose the focus.
Hello Markus,
By default, the underlying bound values of XamDataGrid fields are updated when the cell in edit mode loses focus and passes any validation rules that you may have in place. This can be changed by changing the FieldSettings.DataItemUpdateTrigger property on either the entire XamDataGrid, or the Field itself. This property resolves to "OnLeaveCell" by default, but if you change it to "OnCellValueChange" the data item will be updated on each key-stroke. The code for this would look something along the lines of the following:
<ig:XamDataGrid.FieldSettings> <ig:FieldSettings DataItemUpdateTrigger="OnCellValueChange" /> </ig:XamDataGrid.FieldSettings>
Please let me know if you have any other questions or concerns on this matter.
Thanks, that works great.
I have also some code, where I create the Field in code, then the "<ig:FieldSettings DataItemUpdateTrigger="OnCellValueChange"/>" is ignored.
I tried to set it on the field itself, but that property doesn't exist. How to assign it on the field itselft?
Here is my code snippet:
private Field NewField(string colName, string nameId, SortingClassValueType valueType) { Field field = new Field(); field.Name = colName; field.Label = ComposeFieldLabel(nameId, valueType); return field; }
The DataItemUpdateTrigger property does not exist on the Field itself - it exists on the Field's FieldSettings, which can be accessed using the Field.Settings property. As such, you can set this property using the following code:
field.Settings.DataItemUpdateTrigger = DataItemUpdateTrigger.OnCellValueChange;
Thanks! That works.
There is only a minor issue. I am using a DataTable, and when the value is updated, the Row.EndEdit() method is not called. That means, the value is changed, but the State is still "Unchanged", so I have no possibility to check if the DataTable has changes.
Actually, I need that info to enable a save button, when to user changes a value.
Is there a way that the Row.EndEdit() function is called, when the value has changed in the grid?
Currently, the Row.EndEdit() method is called internal to the XamDataGrid when the actual Record that is editing loses focus or deactivates. If you want to force this to fire each time anything changes, I would recommend handling the DataValueChanged event of the XamDataGrid, as this will fire anytime a value changes in the grid. Note, this event is an “opt-in” type of event, and so in order for it to fire, you need to set the XamDataGrid.FieldSettings.DataValueChangedNotificationsActive property to “true.”
From the event handler’s event arguments, you can get the Record that is editing. Using it’s DataItem property, you can get the underlying DataRowView, and from its Row property, you can get the DataRow and call EndEdit() on it.
I am attaching a sample project to demonstrate the above. I hope this helps you.
XDGDataTableEndEditCase.zip