We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

AncestorType for a button inside a column of a Master-Details datagrid

Hi,

I have a button that launch a specifi command inside a column of my datagrid, in the details part of a master-details.

The button command is define as also :

Command="{Binding DataContext.SupprimerVilleCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type syncfusion:SfDataGrid}}}"

But the command is never launched, and an error is displayed in Visual Studio output window :

System.Windows.Data Error: 40 : BindingExpression path error: 'SupprimerDepartementCommand' property not found on 'object' ''EntityCollection`1' (HashCode=39200294)'. BindingExpression:Path=DataContext.SupprimerDepartementCommand; DataItem='DetailsViewDataGrid' (Name=''); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')

What is the correct AncestorType to specify in this case ?

Thanks for your help.

Regards,

3 Replies

JG Jai Ganesh S Syncfusion Team October 26, 2015 12:19 PM UTC

Hi MARQUANT,

Thank you for using Syncfusion Products.

You can achieve your requirement to launch the button command inside the details view datagrid column by setting the AncestorLevel based on the details grid level like the below code example,
Code Example:

<syncfusion:GridTemplateColumn MappingName="CustomerID" syncfusion:FocusManagerHelper.WantsKeyInput="True">

        <syncfusion:GridTemplateColumn.CellTemplate>

                <DataTemplate>

             <Button  Content="Click" syncfusion:FocusManagerHelper.FocusedElement="True"

        Command="{Binding Path=DataContext.ToggleExecuteCommand,RelativeSource={RelativeSource AncestorLevel=2, AncestorType=syncfusion:SfDataGrid}}" />

                </DataTemplate>

       </syncfusion:GridTemplateColumn.CellTemplate>
 </syncfusion:GridTemplateColumn>



We have prepared a sample based on this and you can download the sample from the below location,

Sample: http://www.syncfusion.com/downloads/support/directtrac/145693/ze/MasterDetailsViewDemo-255495418

Please let us know if you need further assistance.

Regards,
Jai Ganesh S


MC MARQUANT Cédric October 26, 2015 05:54 PM UTC

Thanks it works perfectly...


JG Jai Ganesh S Syncfusion Team October 27, 2015 04:20 AM UTC

Hi MARQUANT,

Thank you for the update.

Please let us know if you need further assistance on this.

Regards,
Jai Ganesh S

Loader.
Live Chat Icon For mobile
Up arrow icon