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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Auto generated column complex objects

Thread ID:

Created:

Updated:

Platform:

Replies:

124760 Jun 28,2016 09:14 AM UTC Jun 29,2016 01:40 PM UTC WPF 1
loading
Tags: SfDataGrid
Leclerc Alexandre
Asked On June 28, 2016 09:14 AM UTC

Hello Syncfusion,

I have an app who manages objects to display in datagrid with MVVM in wpf.
The ViewModel is generic and feed the datagrid according the Model type.
The columns are auto generated and I use the annotations to set the display. So far so good.

It blocks when I have complex objects encapsulated in Model.
For example I have a Family object who contains a GroupFamily object. I try to display it like a text, and display it like a combobox for edit.
I used GridTemplateColumn for the example. Like this :

                        <syncfusion:GridTemplateColumn HeaderText="Family Group" MappingName="Group">
                            <syncfusion:GridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock VerticalAlignment="Center" Text="{Binding Path=Group.Name}" />
                                </DataTemplate>
                            </syncfusion:GridTemplateColumn.CellTemplate>
                            <syncfusion:GridTemplateColumn.EditTemplate>
                                <DataTemplate>
                                    <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}},
                                                            Path=DataContext.MenuButtonViewModel.GridViewModel.GrpFamilies}"
                                              SelectedValue="{Binding Path=Group}"/>
                                </DataTemplate>
                            </syncfusion:GridTemplateColumn.EditTemplate>
                        </syncfusion:GridTemplateColumn>

But it not matches with what I'm looking for. I want to display for any complex object this template. How can I do ?
Remain that Model can encapsulate few complex objects.

Thanks for your answer.
Alex.

Jai Ganesh S [Syncfusion]
Replied On June 29, 2016 01:40 PM UTC

Hi Leclerc, 
 
We suspect that you want to bind the complex objects in a column and bind the combobox SelectedItem based on the object. We have prepared the sample based on this and please find the sample from the below location, 
 
   <syncfusion:GridTemplateColumn Width="140" 
                                  HeaderText="Customers.City" 
                                 MappingName="Customers" > 
        <syncfusion:GridTemplateColumn.CellTemplate> 
               <DataTemplate> 
                        <TextBlock Text="{Binding Path=Customers.City}"/> 
                    </DataTemplate> 
                </syncfusion:GridTemplateColumn.CellTemplate> 
                 
                <syncfusion:GridTemplateColumn.EditTemplate> 
                    <DataTemplate> 
                        <ComboBox  ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, 
                                                            Path=DataContext.CompanyItems}" SelectedItem="{Binding Path=Customers.City}" /> 
               </DataTemplate> 
       </syncfusion:GridTemplateColumn.EditTemplate> 
    </syncfusion:GridTemplateColumn> 
 
 
In the above sample, we have a combobox’s ItemsSource in a viewmodel and bind the SelectedItem based on the complex property. 
 
If we misunderstood your requirement, please share the more details about your requirement? This would be more helpful for us to analyze further. 
 
Regards, 
Jai Ganesh S 
 


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

;