I am using Infragistics V16.1 . I am giving snipped of code where the issue occurs
Here ParentColl is ObservableCollection of TreeElement which has children of Type TreeElement bind to XamDataTree.
Xaml:
<ig:XamDataTree x:Name="MyTree" Grid.Row="0" AllowDrop="True" DisplayMemberPath="Name" ItemsSource="{Binding ParentColl}"> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="ParentLayout" TargetTypeName="TreeElement" IsDraggable="True" IsDropTarget="True" DisplayMemberPath="Name"/> </ig:XamDataTree.GlobalNodeLayouts> </ig:XamDataTree>
On the click of a button I am trying to remove the childitem when parent is collapsed . Here is sample
TreeElement ChildItem = Parent.Children.FirstOrDefault();
Parent.Children.Remove(ChildItem);
The System.NullReferenceException is thrown only when Parent is collapsed. Help me find a solution.
Exception Thrown is below:
at Infragistics.Controls.Menus.NodeLayout.UnSubscribeForNotificationsForNodeData(Object nodeData) at Infragistics.Controls.Menus.NodesManager.DataManager_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at Infragistics.DataManagerBase.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at Infragistics.DataManagerBase.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs e) at Infragistics.DataManager`1.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs e) at Infragistics.DataManagerBase.<SetDataSource>b__9(DataManagerBase instance, Object s, NotifyCollectionChangedEventArgs e) at Infragistics.WeakEventHandler`3.OnEvent(Object source, TEventArgs eventArgs) at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index) at System.Collections.ObjectModel.Collection`1.Remove(T item)
Hello Vetriselvan,XamDataTree nodes are virtualized to improve the performance when the control has a large amount of items. When you try to access a child element of a node which is not expanded, this child element is not rendered because it is not in view and that will cause a NullReferenceException.To access the UI element which is not in view you can turn off the virtualization by placing the XamDataGrid in a container which measures its children with infinite height e.g. StackPanel or ScrollViewer. Another approach would be to operate with the data source of the XamDataTree and remove the element from there so it is no longer displayed as a node.Please feel free to let me know if you have any questions.
I am not accessing the UI Element. I am only removing from the datasource . Can you give me sample if what i am doing below is not what you are referrring to
Please see the piece of code
Here ParentColl is the datasource.
ObservableCollection<TreeElement> ParentColl;
TreeElement Parent = ParentColl[1];
<ig:XamDataTree x:Name="MyTree" AllowDrop="True" DisplayMemberPath="Name" ItemsSource="{Binding ParentColl}"> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="ParentLayout" TargetTypeName="TreeElement" IsDraggable="True" IsDropTarget="True" DisplayMemberPath="Name"/> </ig:XamDataTree.GlobalNodeLayouts> </ig:XamDataTree>
Adding the Class for Parent for your reference:
public class TreeElement
{ private ObservableCollection<TreeElement> _childNodes;
public string Name { get; set; }
public ObservableCollection<TreeElement> Children { get { if (this._childNodes == null) this._childNodes = new ObservableCollection<TreeElement>();
return this._childNodes; } }
}
Hello Vetriselvan,I have put together a sample project using the code snippets you shared. The child node of the second parent is deleted when the user clicks the Delete button. Since in the code snippet the item is removed from the source collection, the XamDataTree node is deleted without any exceptions. Please feel free to use the sample project as a starting point when implementing this functionality. And do not hesitate to let me know if you have any questions or concerns.
I just ran the sample without any modification as you have given.
The same exception "Object reference not set to an instance of an object" occurs at the line
at Infragistics.Controls.Menus.NodeLayout.UnSubscribeForNotificationsForNodeData(Object nodeData) at Infragistics.Controls.Menus.NodesManager.DataManager_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at Infragistics.DataManagerBase.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at Infragistics.DataManagerBase.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs e) at Infragistics.DataManager`1.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs e) at Infragistics.DataManagerBase.<SetDataSource>b__9(DataManagerBase instance, Object s, NotifyCollectionChangedEventArgs e) at Infragistics.WeakEventHandler`3.OnEvent(Object source, TEventArgs eventArgs) at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index) at System.Collections.ObjectModel.Collection`1.Remove(T item) at XamDataTreeDeleteNode.MainWindow.btnDelete_Click(Object sender, RoutedEventArgs e)
I guess the child element is not available as virtualization is on
Is there any way you can turn off virtualization by a flag?
Let me know if any solution is there
Hello Pranav,I can confirm that the NullReferenceException when a node is removed is fixed and is not reproducible in versions ‘15.2.20152.2212’, ‘16.1.20161.2174’ and ‘16.2.20162.2045’.
Please let me know if you have any other questions.
Please ignore previous post. I misread the version in your post. I was testing with version ‘16.1.20161.2056’ and the issue has been resolved for versions ‘15.2.20152.2212’, ‘16.1.20161.2174’ and ‘16.2.20162.2045’. Please confirm if this is correct. I have yet to test with versions that you have stated.
Hi,
I used your example with following version '16.1.20161.2056'. I still get the error of null exception. As per your previous post this version should have it resolved, but doesn't seem like it has been resolved for this version. Can you please confirm once again if this version has the issue resolved.
Hello,The fix for issue 221815 was released and is available for versions 15.2.20152.2212, 16.1.20161.2174 and 16.2.20162.2045.I have verified using those versions and the attached sample project that no NullReferenceException is thrown. Please run the sample and let me know if the behavior is different on your side. If the project does not illustrate your scenario correctly, do not hesitate to modify it and upload it back so I can investigate the behavior further.Do not hesitate to ask if you have any questions.
We've encountered the same issue:
Stack below:
at Infragistics.Controls.Menus.NodeLayout.UnSubscribeForNotificationsForNodeData(Object nodeData)
at Infragistics.Controls.Menus.NodesManager.DataManager_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Infragistics.DataManagerBase.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Infragistics.DataManagerBase.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs e)
at Infragistics.DataManager`1.OnDataSourceCollectionChanged(NotifyCollectionChangedEventArgs e)
at Infragistics.DataManagerBase.<SetDataSource>b__9(DataManagerBase instance, Object s, NotifyCollectionChangedEventArgs e)
at Infragistics.WeakEventHandler`3.OnEvent(Object source, TEventArgs eventArgs)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
It seems, that the latest 2016.2 version has the fix.
Regards
Jarek