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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding to parent object in DetailsView

Thread ID:





127458 Nov 16,2016 06:27 PM UTC Nov 21,2016 01:02 PM UTC WPF 3
Tags: SfDataGrid
Asked On November 16, 2016 06:27 PM UTC


I would like to dynamically change the column headers of the detailview depending on the parent object. Is that possible? I want to bind the Header Text to the parent's (NameColumn1). Same for visibility. I think I should use RelativeSource but I don't know how. Here is a quick example:

            ItemsSource="{Binding MyParents}">
                <Syncfusion:GridViewDefinition RelationalColumn="MyChilds">
                            <Syncfusion:GridTextColumn HeaderText="{Binding ??}" ValueBinding="{Binding ValueColumn1, Mode=OneWay}" IsHidden="{Binding ??}"/>

public class ViewModel
    public ObservableCollection<MyParentClass> MyParents { get; set; }
public class MyParentClass
    public bool ShowColumn1 => true;
    public string NameColumn1 => "t1";
    public ObservableCollection<MyChildClass> MyChilds { get; set; }
public class MyChildClass
    public string ValueColumn1 = "foo";

Jai Ganesh S [Syncfusion]
Replied On November 18, 2016 01:48 PM UTC

Hi Philipp, 
You can achieve your requirement for binding the HeaderText and IsHidden for details view column by setting the datacontext for detailsviewdatagrid like below, 
public MainWindow() 
    this.FirstDetailsViewGrid.DataContext = this.DataContext; 
  <syncfusion:GridTextColumn MappingName="OrderID" HeaderText="{Binding Path=HeaderText, Mode=TwoWay}" 
                                        <syncfusion:GridTextColumn MappingName="ProductID" TextAlignment="Right" IsHidden="{Binding Path=IsHide,Mode=TwoWay}" /> 
Jai Ganesh S 

Replied On November 18, 2016 06:45 PM UTC

Thanks for your answer. However this is not what I want to do. For instance, in your example I would like to hide the column 'Order Date' in the detail view if the property IsClosed of the class OrderInfo is true. In other words, depending on the closed information I want to show/hide the Order Date column.  How can I do that?

Thanks for your help,

Jai Ganesh S [Syncfusion]
Replied On November 21, 2016 01:02 PM UTC

Hi Philipp, 
We have analyzed your query. We regret to inform you that, we cannot hide the column of DetailsViewDataGrid based on record. As all DetailsView DataGrid’s in same level shares same settings. If we hide the one DetailsViewDataGrid and it reflects for all DetailsViewDataGrids. By default, all DetailsViewDataGrid should have the same number of columns and with same width. 
Jai Ganesh S 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon