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
close icon

Adding Columns during runtime lead to an exception error

Hi everybody,

I really need you help! I developted a program in C# with WPF.

I have a MainWindows with a frame in it, loading a Page. In this page I used a SfDataGrid. During the runtime I cahnge Visibility of the Frame-Element and remove all columns from the SfDataGrid (Columns Binding to a collection). Since some users complained about problems with filtering and sorting I decided to update the SfDataGrid to the newest Version (16.4460.0.42). Since the update following occurs everytime: When I change the Fram's Visibility to visible for the first time everything works perfectly. But when I change the Frame'sVisibility to Collapsed and then to Visible again and Add Columns to the SfDataGrid the program crashed and tells me:

System.NullReferenceException: "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt."

There are no further information for this error...

This is basically what I do:

public void CreateColumns()
                //this.Dispatcher.BeginInvoke((Action)delegate ()


                AddColumns(); //By leaving this line, where I add Columns to the Collection, there is no error, but of course no columns are being added!!!

            catch (Exception e)


private void AddColumns()
            foreach (Syncfusion.UI.Xaml.Grid.GridColumn column in Columns_Arbeitsvorrat)
                //dtgArbeitsvorrat.Columns.Add(column); //Even if I do not bind the columns to the grid the error occures

This is the DataGrid:
<syncfusion:SfDataGrid Name="dtgArbeitsvorrat"
                                           ItemsSource="{Binding ElementName=dpArbeitsvorratPager, Path=PagedSource}"
                                           SelectedItem="{Binding ElementName=_pagFormularINR, Path=selectedINRFormular}"
                                           Columns="{Binding ElementName=_pagFormularINR, Path=columnCollection}"
                                           SelectionMode="{local:SettingBinding Path=bSettingsMultiSelectionInDataGrid, Converter={StaticResource boolToSelectionModeConverter}}"
                                           GridCopyOption="CopyData, IncludeHeaders"
                                           FilterChanged="dtgArbeitsvorrat_FilterChanged" KeyUp="dtgArbeitsvorrat_KeyUp" 

                                <MenuItem Name="miArbeitsvorrat_CopyListToClipboard" Header="{x:Static p:Resources.Copy}" Click="MenuItem_Click">
                                        <Image Source="/Icons/Copy32x32.png" />

Please tell me if you need more information!

Can you tell me what I'm doing wrong? Or changed anything in the SfDataGrid?

Thank you very much!!!


1 Reply

SP Shobika Palani Syncfusion Team March 13, 2019 01:22 PM UTC

Hi Victor, 

Thank you contacting Syncfusion Support. 

We have prepared sample based on the provided details. But we are unable to reproduce the reported issue in the mentioned version Please find the tested sample from our end in the below link 

Sample Link: 

If still issue is reproduced at your end, please revert us with the modified sample. It will help us to investigate exact cause for the issue and provide better solution at the earliest. 


Live Chat Icon For mobile
Up arrow icon