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

Is it possible to reuse a grid columns definitions?

Thread ID:





123806 Apr 22,2016 01:26 PM UTC Apr 25,2016 12:10 PM UTC WPF 1
Tags: SfDataGrid
sabrina c.
Asked On April 22, 2016 01:26 PM UTC

Maybe this is a silly question, but I have the following scenario.
I have some Hierarchical classes where I have three main collections of Class1, Class2 and Class3, Class 1 has a collection of Class2 inside and Class3 has a collection of Class2 and a Collection of Class1 inside.
In my interface I have three main grids for the collections of Class1, Class2 and Class3 objects, and the Class1 and Class3 grids have a detail grid for the collections contained inside.
The question is, since I have 2 identical grids representing Class2 objects and 2 identical grids representing class 1 objects, is there a way for me to create the Sfdatagrid.columns definition for each object just once and reuse them on grids and detail grids representing the same object? this will allow me to work a little bit less because I have to make the column modifications just once instead of multiple times for each grid definition when changing things during development.
thank you in advance

Farjana Parveen Ayubb [Syncfusion]
Replied On April 25, 2016 12:10 PM UTC

Hi  Sabrina, 
Thank you for contacting Syncfusion support. 
You can achieve your requirement ” Is it possible to reuse a grid columns definitions?” by defining the columns collection in ViewModel  and binding to Columns property in SfDataGrid. 
Please refer the code example and sample in the following location, 
Code Example (XAML): 
      <syncfusion:SfDataGrid  x:Name="dataGrid1" 
                        ItemsSource="{Binding VM1}"> 
                <syncfusion:GridViewDefinition RelationalColumn="Class1Value1"> 
                        <syncfusion:SfDataGrid x:Name="FirstDetailsViewGrid" AutoGenerateColumns="False" 
                         Columns="{Binding Columns, Source={StaticResource viewmodel}, UpdateSourceTrigger=PropertyChanged}" > 
        <syncfusion:SfDataGrid  x:Name="dataGrid2" 
                                Columns="{Binding Columns, Source={StaticResource viewmodel}, UpdateSourceTrigger=PropertyChanged}" 
                                ItemsSource="{Binding VM2}" /> 
        <syncfusion:SfDataGrid  x:Name="dataGrid3" 
                        ItemsSource="{Binding VM3}"> 
                <syncfusion:GridViewDefinition RelationalColumn="Class2Value3"> 
                        <syncfusion:SfDataGrid x:Name="FirstDetailsViewGrid1" AutoGenerateColumns="False" 
                         Columns="{Binding Columns, Source={StaticResource viewmodel}, UpdateSourceTrigger=PropertyChanged}"> 
                <syncfusion:GridViewDefinition RelationalColumn="Class1Value3"> 
                        <syncfusion:SfDataGrid x:Name="FirstDetailsViewGrid2" AutoGenerateColumns="True"> 
Code Example (C# - ViewModel): 
    private Columns columns; 
        public Columns Columns 
                if (columns == null) 
                    columns = GetColumns(); 
                return columns; 
                this.columns = value; 
        protected Columns GetColumns() 
            Columns _columns = new Columns(); 
            GridNumericColumn ProductId; 
            ProductId = new GridNumericColumn() 
                MappingName = "ProductId", 
            GridTextColumn ProductName2; 
            ProductName2 = new GridTextColumn() 
                MappingName = "ProductName2", 
            GridNumericColumn SalesID2; 
            SalesID2 = new GridNumericColumn() 
                MappingName = "SalesID2", 
            return _columns; 
Sample Location: DetailsViewSample
Farjana Parveen A 


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