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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Detail view Columns binding

Thread ID:

Created:

Updated:

Platform:

Replies:

145059 Jun 4,2019 02:19 PM UTC Jun 27,2019 12:23 PM UTC WPF 4
loading
Tags: SfDataGrid
Ondrej Svoboda
Asked On June 4, 2019 02:19 PM UTC

Hello,

I'm binding Columns collection to the view model based on this article: https://help.syncfusion.com/wpf/sfdatagrid/mvvm#bind-columns-from-viewmodel. I want to use it also for detail grid in master-detail setup. It works fine for master grid, but detail grid has always no columns.

Is there a way how to do it?

Thanks

Ondra

Ondrej Svoboda
Replied On June 5, 2019 09:27 AM UTC

Just to clarify what I need: dynamically change detail grid column setup (add, remove, reorder columns) from view model.

Adhikesevan Kothandaraman [Syncfusion]
Replied On June 5, 2019 10:19 AM UTC

Hi Ondra, 

Thanks for using Syncfusion products. 

We are currently analyzing your reported query at our end. We will get back to you with the complete details on this at 7th June, 2019. Meanwhile, If you want to populate the details view grid columns, you can use the AutoGenerateColumns property as true for the details view grid or  manually defining the columns for the details view grid. Refer to the following UG link for defining the columns for the master details view grid, 

Regards, 
Adhi 


Ondrej Svoboda
Replied On June 27, 2019 07:33 AM UTC

Hi,
anything new regarding this topic?

Ondřej

Adhikesevan Kothandaraman [Syncfusion]
Replied On June 27, 2019 12:23 PM UTC

Hi Ondre, 

Regret for the inconvenience caused. 

Since the details view grid is not available in the visual tree, it will not support the binding. Therefore, it will not directly bind to the ViewModel property.  
If you want to bind the columns collection of the DetailsViewDataGrid with ViewModel property, you can use the binding by inheriting Freezable class as below, 
 
Code Snippet: 
public class BindingProxy : Freezable 
{ 
    protected override Freezable CreateInstanceCore() 
    { 
        return new BindingProxy(); 
    } 
 
    public object Data 
    { 
        get { return (object)GetValue(DataProperty); } 
        set { SetValue(DataProperty, value); } 
    } 
 
    public static readonly DependencyProperty DataProperty = 
        DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null)); 
} 
 
And you can bind to the Columns property of columns in DetailsViewDataGrid as like below, 
 
<Syncfusion:SfDataGrid.Resources> 
    <local:BindingProxy x:Key="proxy" Data="{Binding DataContext, ElementName=datagrid}"/> 
</Syncfusion:SfDataGrid.Resources> 
 
<Syncfusion:SfDataGrid.DetailsViewDefinition> 
    <Syncfusion:GridViewDefinition RelationalColumn="EmployeeDetails"> 
        <Syncfusion:GridViewDefinition.DataGrid> 
            <Syncfusion:SfDataGrid x:Name="FirstDetailsViewDataGrid" AutoGenerateColumns="False"  
                                   Columns="{Binding Data.SfGridColumns, Source={StaticResource proxy}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">                            
            </Syncfusion:SfDataGrid> 
        </Syncfusion:GridViewDefinition.DataGrid> 
    </Syncfusion:GridViewDefinition> 
</Syncfusion:SfDataGrid.DetailsViewDefinition> 
 
 

Regards, 
Adhi 


CONFIRMATION

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

Live Chat Icon For mobile
Live Chat Icon