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

Binding to parent object in DetailsView

Hi,

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:

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

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";
}

3 Replies

JG Jai Ganesh S Syncfusion Team 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() 
{ 
    InitializeComponent(); 
    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}" /> 
 
Regards, 
Jai Ganesh S 



PH Philipp 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,
Philipp


JG Jai Ganesh S Syncfusion Team 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. 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon