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

GridViewCheckBoxColumn CheckBox Command

5 Answers 1493 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tegu
Top achievements
Rank 1
Tegu asked on 02 Nov 2017, 10:01 PM

I have the following GridView with the questionable checkbox column. Is there any way to add a command to the checkbox IsChecked property, like an event?

The TestCommand is implemented in the viewmodel and it is working well with a button.

 

<telerik:RadGridView x:Name="SelectedStrategyGroup1_Adjustments_GV"
                     Width="233" Height="214" Canvas.Left="2" Canvas.Top="0" RowHeight="22"
                     AutoGenerateColumns="False"
                     ShowGroupPanel="False" RowIndicatorVisibility="Collapsed"
                     ItemsSource="{Binding VMAdjustmentCollection1, Mode=TwoWay}"
                     ignore:SourceUpdated="SelectedStrategyGroup1_Adjustments_GV_SourceUpdated"
                     >
 
    <telerik:RadGridView.Columns>
        <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsContained, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="S" Width="22" HeaderTextAlignment="Center" TextAlignment="Center" EditTriggers="CellClick" AutoSelectOnEdit="True">
            <telerik:GridViewCheckBoxColumn.CellTemplate>
                <DataTemplate>
                    <CheckBox IsChecked="{Binding IsContained,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                              Command="{Binding Path=TestCommand}"
                              ignore:CommandParameter="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}"/>
                </DataTemplate>
            </telerik:GridViewCheckBoxColumn.CellTemplate>
        </telerik:GridViewCheckBoxColumn>
...         
    </telerik:RadGridView.Columns>
 
</telerik:RadGridView>

 

5 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 07 Nov 2017, 04:03 PM
Hello Istvan,

You cannot change the GridViewCheckBox's CellTemplate and CellEditTemplate, because it is specially designed column. However you can use a GridViewDataColumn and set its templates like so:

<telerik:GridViewDataColumn DataMemberBinding="{Binding IsContained, Mode=TwoWay}" Header="S" Width="22" HeaderTextAlignment="Center"
                                            TextAlignment="Center" EditTriggers="CellClick">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:GridViewCheckBox IsChecked="{Binding IsContained, Mode=TwoWay}"  />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate >
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding IsContained, Mode=TwoWay}" Command="{Binding TestCommand}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

I have set the CellTemplate and CellEditTemplate to a GridViewCheckBox and a CheckBox respectively, the same way as the GridViewCheckBoxColumn structure.

You can also consider using the EventToCommandBehavior to handle the event in your viewmodel.

I hope you find this helpful. Don't hesitate to contact us if you have any further questions.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Jonathan
Top achievements
Rank 1
answered on 21 Mar 2019, 07:02 PM
This is not working for me. :-/
0
Jonathan
Top achievements
Rank 1
answered on 21 Mar 2019, 07:06 PM

Here is my code:

<telerik:GridViewDataColumn Header="Approved"                                                     DataMemberBinding="{Binding IsApproved, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"                                                     Width="Auto"                                                     MinWidth="75"                                                     EditTriggers="CellClick"                                                     IsFilterable="False">                        <telerik:GridViewDataColumn.CellTemplate>                            <DataTemplate>                                <telerik:GridViewCheckBox IsChecked="{Binding IsApproved, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />                            </DataTemplate>                        </telerik:GridViewDataColumn.CellTemplate>                        <telerik:GridViewDataColumn.CellEditTemplate>                            <DataTemplate>                                <CheckBox IsChecked="{Binding IsApproved, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"                                     Command="{Binding ApprovalStatusEditCommand, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />                            </DataTemplate>                        </telerik:GridViewDataColumn.CellEditTemplate>                    </telerik:GridViewDataColumn>

 

My ApprovalStatusEditCommand is not being fired. Also, as a side note, the DataMemberBinding is not necessary. Even without it the "IsChecked" bindings seem to be updating the object - even though the "IsApproved" is underlined as "cannot resolve."

0
Vladimir Stoyanov
Telerik team
answered on 25 Mar 2019, 04:00 PM
Hello Jonathan,

It seems that you have managed to achieve what you were going for based on the other forum thread that you have opened: GridViewCheckBoxColumn CheckBox Command part II.

I do hope that this is indeed the case. Of course, if you need any further assistance, do not hesitate to write back in the other thread or in a new support ticket

Regards,
Vladimir Stoyanov
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.
0
Jonathan
Top achievements
Rank 1
answered on 25 Mar 2019, 04:08 PM

Hello Vladimir,

Thank you for checking with me and yes - thankfully I was able to resolve the issue.

Best,

Jonathan

Tags
GridView
Asked by
Tegu
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or