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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Adding Columns during runtime lead to an exception error

Thread ID:

Created:

Updated:

Platform:

Replies:

143265 Mar 12,2019 09:07 AM UTC Mar 13,2019 01:22 PM UTC WPF 1
loading
Tags: SfDataGrid
Victor Dienstbier
Asked On March 12, 2019 09:07 AM UTC

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()
        {
            try
            {
                //this.Dispatcher.BeginInvoke((Action)delegate ()
                //{
                dtgArbeitsvorrat.Columns.Suspend();

                dtgArbeitsvorrat.Columns.Clear();
                dtgArbeitsvorrat.ClearFilters();

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

                dtgArbeitsvorrat.Columns.Resume();
                dtgArbeitsvorrat.RefreshColumns();
                //});
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

        }

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
                columnCollection.Add(column);
            }
        }

This is the DataGrid:
<syncfusion:SfDataGrid Name="dtgArbeitsvorrat"
                                           ItemsSource="{Binding ElementName=dpArbeitsvorratPager, Path=PagedSource}"
                                           SelectedItem="{Binding ElementName=_pagFormularINR, Path=selectedINRFormular}"
                                           SortColumnsChanging="dtgArbeitsvorrat_SortColumnsChanging"
                                           Columns="{Binding ElementName=_pagFormularINR, Path=columnCollection}"
                                           ShowRowHeader="True"
                                           SelectionMode="{local:SettingBinding Path=bSettingsMultiSelectionInDataGrid, Converter={StaticResource boolToSelectionModeConverter}}"
                                           MinHeight="50"
                                           AllowDraggingColumns="True"
                                           AllowDeleting="False"
                                           AllowEditing="False"
                                           LiveDataUpdateMode="AllowSummaryUpdate"
                                           ShowSortNumbers="True"
                                           AllowFiltering="True"
                                           AutoGenerateRelations="False"
                                           AutoGenerateColumns="False"
                                           MouseDoubleClick="dtgArbeitsvorrat_MouseDoubleClick" 
                                           SelectionChanged="dtgArbeitsvorrat_SelectionChanged"
                                           GridCopyOption="CopyData, IncludeHeaders"
                                           NavigationMode="Row"
                                           AllowResizingColumns="True" 
                                           AllowResizingHiddenColumns="True" 
                                           QueryColumnDragging="dtgArbeitsvorrat_QueryColumnDragging" 
                                           FilterChanged="dtgArbeitsvorrat_FilterChanged" KeyUp="dtgArbeitsvorrat_KeyUp" 
                                           SelectionChanging="dtgArbeitsvorrat_SelectionChanging">

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

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!!!


Victor

Shobika Palani [Syncfusion]
Replied On 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 16.4.0.42. 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. 

Regards, 
Shobika.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;