C1DataGrid binding UpdateSourceTrigger

Posted by: stj on 11 October 2018, 7:05 pm EST

    • Post Options:
    • Link

    Posted 11 October 2018, 7:05 pm EST

    Hi there,

    I have a C1DataGrid binding the ItemsSource to an ObservableCollection.

    The C1DataGrid is editable. When I edit a cell, the setter for the property is called for every key stroke.

    In a Microsoft DataGrid the setter is called when I press Enter.

    I have tried setting UpdateSourceTrigger on the ItemsSource binding to any value possible with no effect.

    Do I have to write out the Column definitions in XAML in order to control when the setter for the property is called or is there a smarter way?

    Best regards,

    SteffenJ

  • Posted 11 October 2018, 9:52 pm EST

    Hi again,

    I made one more test with the C1FlexGrid. C1FlexGrid acts the same way as Microsoft DataGrid.

    I really need a way to make the C1DataGrid act the same way as the others.

    Best regards,

    SteffenJ

  • Posted 14 October 2018, 6:01 pm EST

    Hello Steffen,

    I can observe what you mentioning. This happens because C1Datagrid internally commits the changes upon every input.

    To workaround this, you need to set the UpdateSourceTrigger to LostFocus at the column level, like you mentioned earlier:```

    c1:C1DataGrid.Columns

    <c1:DataGridTextColumn Header=“FirstName” Binding=“{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=LostFocus}” />

    <c1:DataGridTextColumn Header=“LastName” Binding=“{Binding LastName, Mode=TwoWay, UpdateSourceTrigger=LostFocus}” />

    <c1:DataGridNumericColumn Header=“Age” Binding=“{Binding Age, Mode=TwoWay, UpdateSourceTrigger=LostFocus}” />

    <c1:DataGridNumericColumn Header=“Salary” Binding=“{Binding Salary, Mode=TwoWay, UpdateSourceTrigger=LostFocus}” />

    </c1:C1DataGrid.Columns>

    
    Thanks,
    Ruchir
    [zip filename="C1DataGridSample.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-e79f0214-5f15-4e99-bc93-e9a526b4267a.zip[/zip]
  • Posted 22 October 2018, 12:03 am EST

    Hi Ruchir,

    Your answer is very fine. It gave me an idea which I followed.

    Instead of writing all columns by hand in XAML, I made a subscription to the ```

    AutoGeneratingColumn

    private void grd_AutoGeneratingColumn(object sender, C1.WPF.DataGrid.DataGridAutoGeneratingColumnEventArgs e)

    {

    if (e.Column.Name == “Name”)

    {

    C1.WPF.DataGrid.DataGridTextColumn col = (C1.WPF.DataGrid.DataGridTextColumn)e.Column;

    col.Binding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;

    }

    }

    This is less work for me because only a few columns are editable in my case.
    Thanks for answering,
    SteffenJ
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels