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

Auto generated column complex objects

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.

1 Reply

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


Loader.
Up arrow icon