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:

Created:

Updated:

Platform:

Replies:

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

Hi,
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
Sabrina

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" 
                        AutoGenerateColumns="True"  
                        ItemsSource="{Binding VM1}"> 
            <syncfusion:SfDataGrid.DetailsViewDefinition> 
                <syncfusion:GridViewDefinition RelationalColumn="Class1Value1"> 
                    <syncfusion:GridViewDefinition.DataGrid> 
                        <syncfusion:SfDataGrid x:Name="FirstDetailsViewGrid" AutoGenerateColumns="False" 
                         Columns="{Binding Columns, Source={StaticResource viewmodel}, UpdateSourceTrigger=PropertyChanged}" > 
                        </syncfusion:SfDataGrid> 
                    </syncfusion:GridViewDefinition.DataGrid> 
                </syncfusion:GridViewDefinition> 
            </syncfusion:SfDataGrid.DetailsViewDefinition> 
        </syncfusion:SfDataGrid> 
        <syncfusion:SfDataGrid  x:Name="dataGrid2" 
                                Grid.Column="1" 
                                AutoGenerateColumns="False"  
                                Columns="{Binding Columns, Source={StaticResource viewmodel}, UpdateSourceTrigger=PropertyChanged}" 
                                ItemsSource="{Binding VM2}" /> 
        <syncfusion:SfDataGrid  x:Name="dataGrid3" 
                                Grid.Column="2" 
                        AutoGenerateColumns="True"  
                        ItemsSource="{Binding VM3}"> 
            <syncfusion:SfDataGrid.DetailsViewDefinition> 
                <syncfusion:GridViewDefinition RelationalColumn="Class2Value3"> 
                    <syncfusion:GridViewDefinition.DataGrid> 
                        <syncfusion:SfDataGrid x:Name="FirstDetailsViewGrid1" AutoGenerateColumns="False" 
                         Columns="{Binding Columns, Source={StaticResource viewmodel}, UpdateSourceTrigger=PropertyChanged}"> 
                        </syncfusion:SfDataGrid> 
                    </syncfusion:GridViewDefinition.DataGrid> 
                </syncfusion:GridViewDefinition> 
                <syncfusion:GridViewDefinition RelationalColumn="Class1Value3"> 
                    <syncfusion:GridViewDefinition.DataGrid> 
                        <syncfusion:SfDataGrid x:Name="FirstDetailsViewGrid2" AutoGenerateColumns="True"> 
                        </syncfusion:SfDataGrid> 
                    </syncfusion:GridViewDefinition.DataGrid> 
                </syncfusion:GridViewDefinition> 
            </syncfusion:SfDataGrid.DetailsViewDefinition> 
        </syncfusion:SfDataGrid> 
 
Code Example (C# - ViewModel): 
 
    private Columns columns; 
        public Columns Columns 
        { 
            get 
            { 
                if (columns == null) 
                    columns = GetColumns(); 
                return columns; 
            } 
            set 
            { 
                this.columns = value; 
                OnPropertyChanged("Columns"); 
            } 
        } 
 
        protected Columns GetColumns() 
        { 
            Columns _columns = new Columns(); 
 
            GridNumericColumn ProductId; 
            ProductId = new GridNumericColumn() 
            { 
                MappingName = "ProductId", 
                 
            }; 
            _columns.Add(ProductId); 
 
            GridTextColumn ProductName2; 
            ProductName2 = new GridTextColumn() 
            { 
                MappingName = "ProductName2", 
 
            }; 
            _columns.Add(ProductName2); 
 
            GridNumericColumn SalesID2; 
            SalesID2 = new GridNumericColumn() 
            { 
                MappingName = "SalesID2", 
 
            }; 
            _columns.Add(SalesID2); 
 
 
            return _columns; 
        } 
 
Sample Location: DetailsViewSample
 
 
Regards, 
Farjana Parveen A 


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.

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

;