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

Serialization of GridTemplateColumn

Hi,
I have added a GridTemplateColumn to my DataGrid. Inside the CellTemplate are two Buttons. After serialization and deserialization the Buttons are gone.
I have changed your Serialization sample to demonstrate the Problem - I have added this column:

<syncfusion:GridTemplateColumn HeaderText="Test" MappingName="SupplierID">

<syncfusion:GridTemplateColumn.CellTemplate>

<DataTemplate>

<Button Content="{Binding SupplierID}" />

</DataTemplate>

</syncfusion:GridTemplateColumn.CellTemplate>

</syncfusion:GridTemplateColumn>


After clicking Serialize and then Deserialize the Buttons are gone.
Is there a way to use der GridTemplateColumn with serialization?

Thanks

Kurt

3 Replies

SP Sowndaiyan Paulpandi Syncfusion Team March 9, 2016 01:12 PM UTC

Hi Kurt,

Thanks for contacting Syncfusion Support.

We regret to inform you that in SfDataGrid it is not possible to Serialize GridTemplateColumn. However you can achieve your requirement by manually adding the CellTemplate to the GridTemplateColumn while performing the Deserialization like the below code example. We have prepared a work around sample as per your requirement and you can  download the same from the below location,

C#


private
static void OnExecuteDeserialize(object sender, ExecutedRoutedEventArgs args)

        {

            var dataGrid = args.Source as SfDataGrid;

            if (dataGrid == null) return;

            var options = args.Parameter as DeserializationOptions;

            try

            {

                using (var file = File.Open("DataGrid.xml", FileMode.Open))

                {

                    dataGrid.Deserialize(file, options);


                    var col = dataGrid.Columns.FirstOrDefault(column => column.MappingName == "SupplierID");


                    col.CellTemplate = App.Current.Resources["TemplateColumn"] as DataTemplate;

                  

                }

            }

            catch (Exception)

            {


            }

        }




Sample :  http://www.syncfusion.com/downloads/support/forum/123323/ze/SerializationDemo-380074400



Regards,

Sowndaiyan



KZ Kurt Zimmermann March 10, 2016 08:11 PM UTC

Thank you for the fast Response - this works perfect!

Regards,

Kurt


SV Srinivasan Vasu Syncfusion Team March 11, 2016 04:23 AM UTC

Hi Kurt,

Thanks for the update.


Please let us know if you need further assistance.
Regards,
Srinivasan

Loader.
Up arrow icon