This is a migrated thread and some comments may be shown as answers.

GridViewCheckBoxColumn - EditMode OnValueChange

1 Answer 30 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hans
Top achievements
Rank 1
Veteran
Hans asked on 25 Mar 2019, 12:35 PM

Hi,

I have a GridView with a GridViewCheckBoxColumn that is bound to a 'IsSelected' property of an entity. 

<telerik:GridViewCheckBoxColumn Header="" DataMemberBinding="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoSelectOnEdit="True" EditTriggers="CellClick" >

 

The entity also has a property 'NetLength'.  The entities are grouped by some other property.  Each time an entity gets checekd or unchecked, I need to calculate the sum of NetLength.  I've done that by adding a custom aggregate funcion in code behind.

var selectedItemsTotalMetersfunction = new AggregateFunction<PartNumberModel, decimal>();
selectedItemsTotalMetersfunction.AggregationExpression = pnrs => pnrs.Where(pn => pn.IsSelected).Sum(pn => pn.NetLength ?? 0);
selectedItemsTotalMetersfunction.Caption = "Meters:";
grdShippingOrder.Columns["NetLength"].AggregateFunctions.Add(selectedItemsTotalMetersfunction);

 

Now, all this works fine except for the fact that the bounded property 'IsSelected' only gets changed when the row changes.  Also my total of NetLength is recalculated only when row changes.  How can I force the calculation to be done at the moment the checkbox is checked/unchecked ?

In Winforms, the GridViewCheckBoxColumn has a property 'EditMode' which can be set to 'OnValueChange'.  Is there something similar in WPF ?

Regards,
Hans

 

1 Answer, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 28 Mar 2019, 11:16 AM
Hello Hans,

Thank you for the code snippets. 

The GridViewCheckBoxColumn does not support this case, to trigger property change on checking the checkbox. What I can suggest you is to define a CheckBox in the CellTemplate of a GridViewDataColum and set the UpdateSourceTrigger property in the binding to PropertyChanged.  
<telerik:GridViewDataColumn>
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

More information about the CellTemplate and CellEditTemplate can be found in the Setting CellTemplate and CellEditTemplate help article in our documentation.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Hans
Top achievements
Rank 1
Veteran
Answers by
Dinko
Telerik team
Share this question
or