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