6

I have SEVERAL XamDataGrids in my application, and I want all of them to enable the respective Save buttons as soon as the user changes a checkbox in them. This currently doesn't happen until I leave the cell or press enter etc, because the cell is still in edit mode. I know how to fix this using a post I found in code-behind:

private void XamDataGrid_CellChanged(object sender, Infragistics.Windows.DataPresenter.Events.CellChangedEventArgs e)
        {
            e.Cell.Record.SetCellValue(e.Cell.Field, e.Editor.Value, true);
        }

But how can i handle this for ALL my grid across the app, without putting this in code-behind for every grid? I am using MVVM and would prefer to not have any code behind, if possible. If I have to, i will, but i defintitely don't want it in the code behind in 17 different files with grids. Maybe a behavior?

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • This sounds like you need to add the `Binding.UpdateSourceTrigger` property to a value of `PropertyChanged` on your `Binding`s... it sounds like they are currently set to `LostFocus`? – Sheridan Oct 24 '13 at 14:26
  • sounds like but isn't, the cell in a xamdatagrid is "still in edit mode", so setting UpdateSourceTrigger to PropertyChanged has no effect, in fact, that's the default i belive – Theodosius Von Richthofen Oct 24 '13 at 15:36
  • 1
    You can have code-behind in MVVM. It just can't be business logic. – Jason Tyler Oct 24 '13 at 17:02
  • You could create a new class and inherit `XamDataGrid`. With that, you could override the protected method `OnCellChanged` and add the implementation you posted. That would remove the necessity of adding code-behind to all your files. – Jason Tyler Oct 24 '13 at 17:08
  • that's a good idea and probably what i will do. i still want to hear from someone who can tell me if I can( (should?) accomplish this via a behavior and how to do that. – Theodosius Von Richthofen Oct 24 '13 at 17:11

2 Answers2

7

You need to set the DataItemUpdateTrigger to OnCellValueChange.

Default value for all fields in a XamDataGrid

<igDP:XamDataGrid.FieldSettings>
    <igDP:FieldSettings 
        DataItemUpdateTrigger="OnCellValueChange" />
</igDP:XamDataGrid.FieldSettings>
  • I believe this could easily be applied as a style for all XamDataGrids.

For an individual Field

<igDP:Field Label="" Name="IsSelected" >
    <igDP:Field.Settings>
        <igDP:FieldSettings DataItemUpdateTrigger="OnCellValueChange" />
    </igDP:Field.Settings>
</igDP:Field>
FodderZone
  • 863
  • 12
  • 27
1

DataItemUpdateTrigger property is available in FieldSettings class in NetAdvantage 2013 v. 2 or later.

NG_
  • 6,895
  • 7
  • 45
  • 67
Eduard Rappa
  • 23
  • 1
  • 6