Serialize Problem with SerializeColumns option

Hello,

I have a problem when I serialize. I have this sfDataGrid :
        <syncfusion:SfDataGrid x:Name="datagridProject" ItemsSource="{Binding Elements}" SelectedItem="{Binding SelectedElement}" Grid.Column="2" Margin="0,50,10,0"
                               SelectionMode="Extended" ColumnSizer="Star" ScrollViewer.HorizontalScrollBarVisibility="Hidden" RowHeight="40" AlternatingRowStyle="{StaticResource AlternatingRowStyle}"
                               AllowDraggingColumns="True" AllowFiltering="True" AutoGenerateColumns="False" NavigationMode="Row" ShowGroupDropArea="True">
            <syncfusion:SfDataGrid.Columns>
<i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <mvvmlight:EventToCommand Command="{Binding ShowEdit}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="SelectionChanged">
                    <mvvmlight:EventToCommand Command="{Binding SelectionChanged}" CommandParameter="{Binding SelectedItems, ElementName=datagridProject}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <syncfusion:SfDataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding ShowAdd}" Header="Ajouter">
                        <MenuItem.Icon>
                            <Image Source="/EllyosERP;Component/Resource/Image/Icon/V1/add.png" Width="15" Height="15"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="{Binding ShowEdit}" Header="Modifier">
                        <MenuItem.Icon>
                            <Image Source="/EllyosERP;Component/Resource/Image/Icon/V1/pencil.png" Width="15" Height="15"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="{Binding DetailViewModel.ShowSelectModelPrint}" Header="Imprimer">
                        <MenuItem.Icon>
                            <Image Source="/EllyosERP;Component/Resource/Image/Icon/V1/print.png" Width="15" Height="15"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="{Binding Delete}" Header="Supprimer">
                        <MenuItem.Icon>
                            <Image Source="/EllyosERP;Component/Resource/Image/Icon/V1/trash.png" Width="15" Height="15"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </syncfusion:SfDataGrid.ContextMenu>
                <syncfusion:GridTemplateColumn AllowFiltering="False" AllowSorting="False" Width="10" HeaderText="Color">
                    <syncfusion:GridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Width="5" Fill="{Binding MarkerColor}" />
                            </StackPanel>
                        </DataTemplate>
                    </syncfusion:GridTemplateColumn.CellTemplate>
                </syncfusion:GridTemplateColumn>
                <syncfusion:GridTextColumn HeaderText="N" DisplayBinding="{Binding No}" Width="50"/>
                <syncfusion:GridTextColumn HeaderText="Nom" DisplayBinding="{Binding Name}" Width="350"/>
                <syncfusion:GridDateTimeColumn HeaderText="Date création" DisplayBinding="{Binding CreationDate, StringFormat=\{0:d\}}" Width="120"/>
                <syncfusion:GridImageColumn AllowFiltering="False" HeaderText="Privé" Width="35" ImageHeight="16" ImageWidth="16"
                                            DisplayBinding="{Binding PrivateImage, TargetNullValue={x:Null}}" />
                <syncfusion:GridTextColumn HeaderText="Client" DisplayBinding="{Binding Customer.Name}"/>
                <syncfusion:GridTextColumn HeaderText="Adresse" DisplayBinding="{Binding MainAddressVM.Street1}"/>
                <syncfusion:GridTextColumn HeaderText="Code postal" DisplayBinding="{Binding MainAddressVM.Zip}" Width="100"/>
                <syncfusion:GridTextColumn HeaderText="Ville" DisplayBinding="{Binding MainAddressVM.City}"/>
                <syncfusion:GridTextColumn HeaderText="État" DisplayBinding="{Binding ProjectState.Value}"/>
                <syncfusion:GridTextColumn HeaderText="Description" DisplayBinding="{Binding Description}"/>
            </syncfusion:SfDataGrid.Columns>

And when I try to serialize I have an error : 
System.InvalidOperationException: ColumnName cannot be NULL
   at Syncfusion.Data.Extensions.PropertyDescriptorExtensions.GetPropertyDescriptor(PropertyDescriptorCollection pdc, String columnName)
   at Syncfusion.UI.Xaml.Grid.GridColumn.GetRowFilterType()
   at Syncfusion.UI.Xaml.Grid.GridColumn.get_FilterRowCondition()
   at Syncfusion.UI.Xaml.Grid.SerializationController.StoreGridColumnProperties(GridColumn column, SerializableGridColumn serializableColumn)
   at Syncfusion.UI.Xaml.Grid.SerializationController.StoreGridColumns(SfDataGrid dataGrid, SerializationOptions serializeOptions)
   at Syncfusion.UI.Xaml.Grid.SerializationController.StoreGridSettings(SerializationOptions serializeOptions)
   at Syncfusion.UI.Xaml.Grid.SerializationController.Serialize(Stream stream, SerializationOptions serializeOptions)
   at Syncfusion.UI.Xaml.Grid.SfDataGrid.Serialize(Stream stream, SerializationOptions options)
   at EllyosERP.View.ProjectList.<Serialize_Click>d__2.MoveNext() in
...\Project\View\ProjectList.xaml.cs:ligne 64

I think it is the color columns but i'm not sure and i don't have any idea how to solve this problem.

My second problem it's how deserialize at the openning moment of the sfDataGrid, with a memStream because all the configuration are in a database and all the data transits by a webService ?

Thanks !

6 Replies

GT Gnanasownthari Thirugnanam Syncfusion Team February 16, 2018 03:37 AM UTC

Hi Joshua, 
  
Please find the response for your queries, 
  
Query 1 : System.InvalidOperationException: ColumnName cannot be NULL 
We have noticed in your code snippet, you didn’t provide MappingName for GridTemplateColumn (which is bounded with MarkerColor). MappingName is necessary for all column. 
Query 2 : how deserialize at the openning moment of the sfDataGrid 
We already have an Serialization and Deserialization sample in our dashboard. For you reference we have  attached the sample in below mentioned location. 
  
  
You can get the sample from dashboard from below path location. 
  
\{installed location} \Syncfusion\EssentialStudio\{installedVersion}\WPF \ SfGrid.WPF\Samples\ SerializationDemo\. 
    
  
You can refer the below UG links for more details. 
  
If given requirement does not meet your requirement please share more details about your requirement like video, sample, screenshot that will be helpful to provide appropriate solution at the earliest. 
  
  
Regards, 
Gnanasownthari T. 



JL joshua liaud February 19, 2018 10:14 AM UTC

Hello Gnanasownthari,

The solution is ok for the first query the second is under-construction, but i have a other problem ! It's with the GridImageColumn, because the serialization replace this on GridTextColumn. And if I replace GridTextColumn by GridImageColumn before the deserialize method visual Studio catch a exception which say : the deserializer does not know of any type mapped to this name... 

Do you have a solution for that ?

Thank for your help !

Joshua LIAUD.


JL joshua liaud February 20, 2018 05:20 PM UTC

Hello Gnanasownthari,

Even if, I look in the code in this location : \{installed location} \Syncfusion\EssentialStudio\{installedVersion}\WPF \ SfGrid.WPF\Samples\ SerializationDemo\, I dont found the resolution at this problem :

Message = "The object reference is not defined to an instance of an object."
Source = "Syncfusion.SfGrid.WPF"
   at Syncfusion.UI.Xaml.Grid.GridModel.ResetColumns(Boolean isBatchUpdate)
   at Syncfusion.UI.Xaml.Grid.GridModel.RefreshBatchUpdate(NotifyCollectionChangedAction action, Boolean isProgrammatic)
   at Syncfusion.UI.Xaml.Grid.SerializationController.SetProperties(DeserializationOptions deserializationOptions)
   at Syncfusion.UI.Xaml.Grid.SerializationController.ReloadGrid(SerializableDataGrid dataGrid, DeserializationOptions deserializationOptions)
   at Syncfusion.UI.Xaml.Grid.SerializationController.Deserialize(Stream stream, DeserializationOptions deserializeOptions)
   at Syncfusion.UI.Xaml.Grid.SfDataGrid.Deserialize(Stream stream)
   at EllyosERP.Helper.UserSettingHelper.Deserialize(SfDataGrid datagrid) in 
   ..\Helper\UserSettingHelper.cs:ligne 33


This problem occur when I deserialize in sfDataGrid !
If you need more informations about my view or my ViewModel, do not hesitate to ask to me !


My first query is complete without problem, it's fine! 

Thanks for that, and for your help.

Joshua LIAUD




JG Jai Ganesh S Syncfusion Team February 21, 2018 02:09 AM UTC

Hi Joshua,  
We regret to inform you that, currently we do not have the direct Serialization/Deserialization support for GridImageColumn in SfDataGrid. However, you can achieve your requirement by manually adding the images into the GridImageColumn while performing the Deserialization. We have prepared a work around sample as per your requirement and you can download the same from the below location, 
<syncfusion:GridImageColumn MappingName="ImageLink" ImageHeight="50" ImageWidth="50" 
                                            HeaderText="Profile Pic"  
                                            ValueBinding="{Binding Path=ImageLink, Converter={StaticResource stringToImageConverter}}" /> 
 
private void Deserialize(object sender, RoutedEventArgs e) 
        { 
            if (dataGrid == null) return; 
            var options = new DeserializationOptions(); 
            try 
            { 
                using (var file = File.Open("DataGrid.xml", FileMode.Open)) 
                { 
                    dataGrid.Deserialize(file, options); 
                    foreach(var col in dataGrid.Columns) 
                    { 
                        if(col.MappingName == "ImageLink") 
                        { 
                            var index = dataGrid.Columns.IndexOf(col); 
                            dataGrid.Columns.Remove(col); 
 
                            var converter = new StringToImageConverter(); 
 
                            dataGrid.Columns.Insert(index,new GridImageColumn() { 
                                MappingName  = col.MappingName, 
                                ValueBinding = new Binding("ImageLink") { Converter = converter } 
                            }); 
                        } 
                    } 
                } 
            } 
            catch (Exception) 
            { 
            } 
        } 
 
Could you please check the above sample and you can manually adding the images into the GridImageColumn while performing the Deserialization in your application. If you still facing the exception for trying the above solution then please replicate the issue in above sample. This would be more helpful for us to proceed further. 
Regards, 
Jai Ganesh S


JL joshua liaud February 21, 2018 07:53 AM UTC

Hello, thanks for your reply, but this solution isn't enought generic, but we foud the solution ! We just replace the 'GridImageColumn' by 'GridTemplateColumn' and apparently it works. The problem have changed, know when we open the datagrid we have the message "The object reference is not defined to an instance of an object." ... (message in the last post) and the deserialization works partially the the sort, the group, the resize the works (they are correctly serialize and deserialize) but the filter in a columns don't work.

Thanks again for your replies!

Joshua L


GT Gnanasownthari Thirugnanam Syncfusion Team February 23, 2018 04:03 AM UTC

Hi Joshua, 

We are unable to reproduce the reported filtering issue while Serialize and  Deserialize the GridTemplateColumn (Image is loaded inside the GridTemplateColumn) in our side. For your reference we have attached the tested sample in below mentioned location. In that sample we have loaded the image in GridTemplateColumn based on your given update. 


Please share the below needed details to us that will be helpful to provide appropriate solution at the earliest. 

  1. If it is possible please share your application which reproduces the issue.
  2. Otherwise please revert to us with modified sample based on your application scenario.
  3. Please share the replication procedure for the reported issue.
  4. Please share the details how you have Serialize and Deserialize in your application along with the customization details if you did in your sample with SfDataGrid control.

Regards, 
Gnanasownthari  


Loader.
Up arrow icon