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

Checkbox in header triggers command "sometimes"

2 Answers 257 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Veteran
Robert asked on 12 Oct 2020, 11:58 AM

The strangest thing is happening with my GridView when I try to add a custom datacolumn with a checkbox in and a GridViewColumn.Header, to add anothner checkbox, that should select all checkboxes in the list, pretty standard. 

I have the code below, but when I click  the "check all"-checkbox, I do not get the Command send to my event handler, nothing happens. Now the strange part

If I, while running the application, change the markup (below) AncestorType={x:Type UserControl}}, to AncestorType={x:Type local:MyView}} it works, I get my event. Hip horray, right? Nope. If I restart the application, nothing happens again, until I change it back to the original and things are working again

 

Why, oh Telerik-Gods, why! :D

snippet below:

 

<telerik:GridViewColumn  >
    <telerik:GridViewColumn.Header>
        <CheckBox IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.IsAllChecked, Mode=TwoWay}"                                                                                   
                    Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectAllRowsCommand}">
              

        </CheckBox>
    </telerik:GridViewColumn.Header>


2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
Veteran
answered on 12 Oct 2020, 12:16 PM
...so to clarify, both versions ofAncestorType works, (my view and UserContro), but I need to touch the file at runtime to get the Command to trigger. I have also a Button that triggers that Command everytime, like a Champ
0
Dilyan Traykov
Telerik team
answered on 15 Oct 2020, 10:19 AM

Hello Robert,

Thank you for the provided code snippet.

Based on it, I tried replicating the issue you described in a small sample project, however, the command is invoked successfully each time the checkbox is clicked at my end. Can you please have a look and let me know if I'm missing something of importance?

With your description in mind, it seems that the binding is not evaluated initially and is only reevaluated once you change the markup. I assume that this has to do with the exact position of the checkbox in the visual tree so please specify what other controls/panels hold the RadGridView instance so that I can further investigate.

I will be awaiting your reply.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Robert
Top achievements
Rank 1
Veteran
Answers by
Robert
Top achievements
Rank 1
Veteran
Dilyan Traykov
Telerik team
Share this question
or