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

Embedded grid into Cell

I want to embed a grid into a column cell which based on different condition will show different grid. Is there a way to achieve this? I am using CellTemplateSelector datatemplate to do it, but when the datatemplate is SfDataGrid, it shows exception "source is not IEnumerable<>".

Thanks!



9 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team June 5, 2015 04:04 PM UTC

Hi Tommie, 

Thank you for using Syncfusion products. 

We analyzed your query but we are unable to reproduce the reported issue at our end. We have prepared simple sample based on your requirement. Please review the implementation in this sample.  If you are still seeing the same issue, please modify this sample to reproduce the issue and send the modified sample back to us. This will help us to proceed further. 

Sample: http://www.syncfusion.com/downloads/support/forum/119319/ze/CellTemplateSelector_SfDataGrid580013410 

Please let us know if you have any concerns. 

Regards,

Muthukumar K



TC Tommie Chen June 9, 2015 08:05 PM UTC

 

Hi Muthukumar ,

Thank you for your response. I was using a static CollectionViewSource for cell template, and it fails. After I changed as your sample data structure, it works okay. I have another question:

If CellTemplateSelector and EditTemplateSelector use different template, but it only shows the template from CellTemplateSelector. I also try to modify directly of your sample, it also only display the template from CellTemplateSelector. Even when I change the cell template to a simple template which only holds one textbox or textblock.

Thank you



AN Ashok N Syncfusion Team June 12, 2015 03:29 AM UTC

Hi Tommie,

Thank you for your update.

In SfDataGrid we have support for CellTemplateSelector and EditTemplateSelector to GridTemplateColumn. You can achieve your requirement by using CellTemplateSelector itself. For your reference we provided a sample with both CellTemplateSelector and EditTemplateSelector in our previous update. EditTemplateSelector will be loaded when we edit the GridCell.

Please refer to the following UG link to find more details on the GridTemplateColumn,

UG link: http://help.syncfusion.com/ug/wpf/index.html#!Documents/gridtemplatecolumn.htm

Please let us know if you require further assistance on this.

Thanks,
Ashok



TC Tommie Chen June 12, 2015 04:23 PM UTC

Hi,

I know the document link. I have tried use different EditTemplate in the sample your provide, for example below, and the grid show both Celltemplate and EditTemplate ,and overlap them together. Could you please take a look at it?

  <!-- CellTemplate --> 
        <DataTemplate x:Key="Branch10">
            <Grid>
                <Syncfusion:SfDataGrid x:Name="sfd" AutoGenerateColumns="False" 
                               ItemsSource="{Binding Path=ProductsDetails1}" Background="LightGreen"
                                       ColumnSizer="Auto" RowHeight="20">
                    <Syncfusion:SfDataGrid.Columns>
                        <Syncfusion:GridTextColumn MappingName="ProductId1" />
                        <Syncfusion:GridTextColumn MappingName="ProductName1" />
                    </Syncfusion:SfDataGrid.Columns>
                </Syncfusion:SfDataGrid>
                <TextBlock Text="{Binding ProductName}"/>
            </Grid>
        </DataTemplate>
        <!-- EditTemplate -->
        <DataTemplate x:Key="Branch1">
            <Grid>
                <TextBox Text="{Binding ProductName}"/>
                </Grid>            
        </DataTemplate>



MK Muthukumar Kalyanasundaram Syncfusion Team June 15, 2015 01:58 PM UTC

Hi Tommie,   


We are not able to understand your inquiry. When you set both CellTemplate and EditTemplate, CellTempalte will load for display mode and EditTemplate will load when you are editing the cell. Could you therefore clarify this part of your question:  "Celltemplate and EditTemplate are overlap them together"? Once we understand your requirement, we will be able to provide a solution.


Please review my response.  

Regards,

Muthukumar K



TC Tommie Chen June 16, 2015 02:33 PM UTC

Hi,
I have tried to modify your sample, and couldn't make it work to show different Cell or Edit template. here is the sample. please have a look. 
Thanks again,


Attachment: CellTemplateSelector_SfDataGrid_e0cfa3f.zip


MK Muthukumar Kalyanasundaram Syncfusion Team June 17, 2015 05:59 PM UTC

Hi Tommie, 

Thanks for the update. 

In the sample you have provided TextBlock overlapped with Grid and now we have modified in the below sample, 

Sample: http://www.syncfusion.com/downloads/support/forum/119319/ze/CellTemplateSelector_SfDataGrid-864330432 

Please refer the attached screenshot.

ScreenShot: http://www.syncfusion.com/downloads/support/forum/119319/ze/ScreenSot1159599775 

Could you clarify your requirement based on this sample and update us? This will help us provide a solution. 

Regards,

Muthukumar K



TC Tommie Chen June 18, 2015 08:37 PM UTC

Hi,
Please see my intended changes below,   I use TextBlock in cell template "Branch10",  and TextBox  as in Edit template "Branch1". But when I double click the cell(want to the edition), it couldn't show TextBox  as in Edit template "Branch1".  Same for edit template  "Branch2", which counld't be shown. "Branch2" is editable, and  have different background color than "Branch1".

Let me know if this is not clear.


   <!-- CellTemplate --> 
        <DataTemplate x:Key="Branch10">
            <Grid VerticalAlignment="Center">                
                <TextBlock Text="{Binding ProductName}" />
            </Grid>
        </DataTemplate>
        <!-- EditTemplate -->
        <DataTemplate x:Key="Branch1">
            <Grid>
                <TextBox Text="{Binding ProductName}"/>
             </Grid>            
        </DataTemplate>
        <DataTemplate x:Key="Branch20">
            <Grid>
                <Syncfusion:SfDataGrid x:Name="sfd" AutoGenerateColumns="False" 
                               ItemsSource="{Binding Path=ProductsDetails1}" Background="LightPink"
                               ColumnSizer="Auto" RowHeight="20">
                    <Syncfusion:SfDataGrid.Columns>
                        <Syncfusion:GridTextColumn MappingName="CustomerId1"/>
                        <Syncfusion:GridTextColumn MappingName="ShipmentDetails1"/>
                    </Syncfusion:SfDataGrid.Columns>
                </Syncfusion:SfDataGrid>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="Branch2">
            <Grid>
                <Syncfusion:SfDataGrid x:Name="sfd" AutoGenerateColumns="False" 
                               ItemsSource="{Binding Path=ProductsDetails1}" Background="Pink"
                               AllowEditing="True"
                               ColumnSizer="Auto" RowHeight="20">
                    <Syncfusion:SfDataGrid.Columns>
                        <Syncfusion:GridTextColumn MappingName="CustomerId1"/>
                        <Syncfusion:GridTextColumn MappingName="ShipmentDetails1"/>
                    </Syncfusion:SfDataGrid.Columns>
                </Syncfusion:SfDataGrid>
            </Grid>
        </DataTemplate>




MK Muthukumar Kalyanasundaram Syncfusion Team June 21, 2015 04:16 PM UTC

Hi Tommie, 

We analyzed your query. Based on your code, seems you are loading one SfDataGrid in CellTemplate and also in EditTemplate of GridTemplateColumn. So when you double click on the DataGrid loading inside template, it will load EditTemplate (which also has DataGrid). Please refer to the screenshot(image1). 

Now if you double click DataGrid inside Cell (Loaded from EditTemplate), TextBox will load for the DataGrid inside DataTemplate. Please refer to the screenshot(image2). This is the behavior of DataGrid.


Screenshothttp://www.syncfusion.com/downloads/support/forum/119319/ze/Screenshot-408070851 

Samplehttp://www.syncfusion.com/downloads/support/forum/119319/ze/CellTemplateSelector_SfDataGrid-399297813  

Do you want to edit the DataGrid inside Main DataGrid Cell?  If so, it is not possible to edit in single click. But you can do this by double click by setting EditTrigger property to MainDataGrid and also by setting DataGrid inside Template. 

Please let us know if we have not addressed your requirement.   

Regards,

Muthukumar K


Loader.
Live Chat Icon For mobile
Up arrow icon