This is a migrated thread and some comments may be shown as answers.

Sys.InvalidOperationException at Collapsing Multiple Nodes in Runtime

6 Answers 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 11 Dec 2009, 11:07 AM
Hi,

I'm developing a Tree wich can dynamically LoadOnDemand/ Expand/ Delete/ Filter and so on. But every here and now I get the following Script Error when I collapse all Nodes in Runtime, via recursiv fetching the TreeNodes with my seperate NodeInformation List.

The Code:
 RadTreeViewItem PUChild = PPUEChild.Items[puCnt] as RadTreeViewItem; 
                                if (GetNodeInformation(PUChild.Name).isExpanded == null || GetNodeInformation(PUChild.Name).isExpanded == true
                                    GetNodeInformation(PUChild.Name).isExpanded = PUChild.IsExpanded = true
                                else 
                                    PUChild.IsExpanded = false

The Error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322)
Timestamp: Fri, 11 Dec 2009 10:41:10 UTC


Message: Sys.InvalidOperationException: ManagedRuntimeError error #4004 in control 'silverlightControlHost': System.ArgumentException: Der Wert liegt außerhalb des erwarteten Bereichs.
   bei MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
   bei MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
   bei MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
   bei System.Windows.UIElement.TransformToVisual(UIElement visual)
   bei Telerik.Windows.Controls.TreeView.TreeViewPanel.GetRectangle(DependencyObject element)
   bei Telerik.Windows.Controls.TreeView.TreeViewPanel.IsInViewport(DependencyObject element)
   bei Telerik.Windows.Controls.TreeView.TreeViewPanel.MeasureOverride(Size constraint)
   bei System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
Line: 453
Char: 17
Code: 0
URI: http://localhost:4044/ScriptResource.axd?d=RLKMRk7gF37BIBEIy5_qn1oEqvyhKmRa-9SCmrxsEFQGLfIoB5vD4BU6rIB9_qECHyB4ng7q2uSTjXzKVEVmcQ2&t=1f24b496

Additional, when my Node has no Children, at the first Click for LoadOnDemand neither the LoadOnDemand Event is fired nor the Expand Event. At the 2nd Click LoadOnDemand is fired.

I don't think that my code will help you much but I post my TreeBuilding Function:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Windows;  
using System.Windows.Controls;  
using Telerik.Windows.Controls;  
  
namespace SilverlightApplication1  
{  
    public partial class MainPage : UserControl  
    {  
        private List<RadTreeViewItem> SortingNodes = null;  
        public Dictionary<Guid, NodeInformation> NodeInformations = new Dictionary<Guid, NodeInformation>();  
        Guid level11 = Guid.NewGuid();  
        Guid level12 = Guid.NewGuid();  
        public MainPage()  
        {  
            InitializeComponent();  
            //this.AddItems(this.treeView1);  
            NodeInformations.Add(new Guid(), new NodeInformation() { id = new Guid(), name = "root", nodeType = NodeType.Root, parent = null });  
  
            NodeInformations.Add(level11, new NodeInformation() { id = level11, name = "Level11", nodeType = NodeType.Level1, parent = new Guid() });  
            NodeInformations.Add(level12, new NodeInformation() { id = level12, name = "Level12", nodeType = NodeType.Level1, parent = new Guid() });  
            BuildTree();  
              
        }  
        private void ClearTree()  
        {  
            treeView1.Items.Clear();  
            treeView1.CheckedItems.Clear();  
  
            SortingNodes = new List<RadTreeViewItem>();  
        }  
        private void BuildTree()  
        {  
            ClearTree();  
  
            AddChildNodes(NodeType.Root);  
            AddChildNodes(NodeType.Level1);  
            AddChildNodes(NodeType.Level2);  
           
  
        }  
  
        private void RadTreeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)  
        {  
            string message = string.Format("[{0}] LoadOnDemand Event Fired", DateTime.Now.ToLongTimeString());  
            this.log.Items.Add(message);  
            Guid level21 = Guid.NewGuid();  
            Guid level22 = Guid.NewGuid();  
            NodeInformations.Add(level21, new NodeInformation() { id = level21, name = "Level21", nodeType = NodeType.Level2, parent = level11 });  
            NodeInformations.Add(level22, new NodeInformation() { id = level22, name = "Level22", nodeType = NodeType.Level2, parent = level12 });  
            BuildTree();  
              
        }  
  
        private void RadTreeView_Expanded(object sender, Telerik.Windows.RadRoutedEventArgs e)  
        {  
            string message = string.Format("[{0}] Expanded Event Fired", DateTime.Now.ToLongTimeString());  
            this.log.Items.Add(message);  
        }  
  
          
        private void AddChildNodes(NodeType nodeType)  
        {  
            List<NodeInformation> list;  
            list = (from e in NodeInformations where e.Value.nodeType.Equals(nodeType) select e.Value).ToList();  
  
            RadTreeViewItem node = null;  
            for (int i = 0; i < list.Count; i++)  
            {  
                node = new RadTreeViewItem();  
                node.Header = list[i].name;  
                node.Name = list[i].id.ToString();  
                node.IsExpanded = true;  
                Telerik.Windows.Controls.ItemsControl parentNode = null;  
  
                switch (nodeType)  
                {  
                    case NodeType.Root:  
                        treeView1.Items.Add(node);  
                        SortingNodes.Add(node);  
                        break;  
                    case NodeType.Level1:  
                    case NodeType.Level2:  
                        parentNode = (from ex in SortingNodes where ex.Name.Equals(list[i].parent.ToString()) select ex).FirstOrDefault();  
                        SortingNodes.Add(node);  
                        break;  
                }  
                if (nodeType != NodeType.Root)  
                {  
                    if (parentNode == null)  
                        MessageBox.Show("No Parent!");  
                    else  
                        parentNode.Items.Add(node);  
                }  
            }  
        }  
  
    }  
    public enum NodeType { Root, Level1, Level2};  
  
    public class NodeInformation  
    {  
        public Guid id;  
        public string name;  
        public Guid? parent;  
        public NodeType nodeType;  
    }  
}  
  


Can anybody help me what I'm doing wrong?

Alex

6 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 16 Dec 2009, 12:42 PM
Hi Alex,

Thank you for your feedback. We are aware of the first issue you described and a fix will be available for this week's internal build. Unfortunately I was not able to reproduce the second issue. I have attached a sample project that shows the order in which LoadOnDemand and Expanded events get fired. Have a look at it and let me know whether I am missing something.


Regards,
Kiril Stanoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alex
Top achievements
Rank 1
answered on 17 Dec 2009, 03:53 PM
Hi Kiril,

thanks for the reply. I played a bit with your Code and now you can see my problem, I used the List to store the nodes for later uses. In our project the Tree will be build completely new multiple times, so I store all Informations in the NodesInformation List. The LoadOnDemand Event is not fired the first time.

I can't load up my solution so here is the code for your project:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Windows; 
using System.Windows.Controls; 
using Telerik.Windows.Controls; 
 
namespace SilverlightApplication1 
    public partial class MainPage : UserControl 
    { 
        private List<RadTreeViewItem> SortingNodes = null
        public Dictionary<Guid, NodeInformation> NodeInformations = new Dictionary<Guid, NodeInformation>(); 
        Guid level11 = Guid.NewGuid(); 
        Guid level12 = Guid.NewGuid(); 
        public MainPage() 
        { 
            InitializeComponent(); 
            //this.AddItems(this.treeView1); 
            NodeInformations.Add(new Guid(), new NodeInformation() { id = new Guid(), name = "root", nodeType = NodeType.Root, parent = null }); 
 
            NodeInformations.Add(level11, new NodeInformation() { id = level11, name = "Level11", nodeType = NodeType.Level1, parent = new Guid() }); 
            NodeInformations.Add(level12, new NodeInformation() { id = level12, name = "Level12", nodeType = NodeType.Level1, parent = new Guid() }); 
            BuildTree(); 
             
        } 
        private void ClearTree() 
        { 
            treeView1.Items.Clear(); 
            treeView1.CheckedItems.Clear(); 
 
            SortingNodes = new List<RadTreeViewItem>(); 
        } 
        private void BuildTree() 
        { 
            ClearTree(); 
 
            AddChildNodes(NodeType.Root); 
            AddChildNodes(NodeType.Level1); 
            AddChildNodes(NodeType.Level2); 
          
 
        } 
 
        private void RadTreeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e) 
        { 
            string message = string.Format("[{0}] LoadOnDemand Event Fired", DateTime.Now.ToLongTimeString()); 
            this.log.Items.Add(message); 
            Guid level21 = Guid.NewGuid(); 
            Guid level22 = Guid.NewGuid(); 
            NodeInformations.Add(level21, new NodeInformation() { id = level21, name = "Level21", nodeType = NodeType.Level2, parent = level11 }); 
            NodeInformations.Add(level22, new NodeInformation() { id = level22, name = "Level22", nodeType = NodeType.Level2, parent = level12 }); 
            BuildTree(); 
             
        } 
 
        private void RadTreeView_Expanded(object sender, Telerik.Windows.RadRoutedEventArgs e) 
        { 
            string message = string.Format("[{0}] Expanded Event Fired", DateTime.Now.ToLongTimeString()); 
            this.log.Items.Add(message); 
        } 
 
         
        private void AddChildNodes(NodeType nodeType) 
        { 
            List<NodeInformation> list; 
            list = (from e in NodeInformations where e.Value.nodeType.Equals(nodeType) select e.Value).ToList(); 
 
            RadTreeViewItem node = null
            for (int i = 0; i < list.Count; i++) 
            { 
                node = new RadTreeViewItem(); 
                node.Header = list[i].name; 
                node.Name = list[i].id.ToString(); 
                node.IsExpanded = true
                Telerik.Windows.Controls.ItemsControl parentNode = null
 
                switch (nodeType) 
                { 
                    case NodeType.Root: 
                        treeView1.Items.Add(node); 
                        SortingNodes.Add(node); 
                        break
                    case NodeType.Level1: 
                    case NodeType.Level2: 
                        parentNode = (from ex in SortingNodes where ex.Name.Equals(list[i].parent.ToString()) select ex).FirstOrDefault(); 
                        SortingNodes.Add(node); 
                        break
                } 
                if (nodeType != NodeType.Root) 
                { 
                    if (parentNode == null
                        MessageBox.Show("No Parent!"); 
                    else 
                        parentNode.Items.Add(node); 
                } 
            } 
        } 
 
    } 
    public enum NodeType { Root, Level1, Level2}; 
 
    public class NodeInformation 
    { 
        public Guid id; 
        public string name; 
        public Guid? parent; 
        public NodeType nodeType; 
    } 
 

Regards,
Alex

0
Miroslav
Telerik team
answered on 23 Dec 2009, 01:25 PM
Hi Alex,

Do you experience this issue with the 2009 Q3 SP1 version of the controls as well?
Have you tried setting this property:

IsExpandOnSingleClickEnabled="True"

Then expanding the item should happen on single click. I updated Kiril's example with this and the TreeView expands on single click.

Sincerely yours,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alex
Top achievements
Rank 1
answered on 11 Jan 2010, 08:14 AM
Hi Miroslav,

I updated the project to the latest release (2009.3.1208.1030). I only deleted the line

treeView1.CheckedItems.Clear();

but the behavior is the same. IsExpandOnSingleClickEnabled makes no difference. I tried the solution on another pc but the behavior is still the same: the Level11 and Level12 node LoadOnDemand Event is not fired the first time.

Shall I send you my solution?

Best Regards,
Alexander
0
Accepted
Miroslav
Telerik team
answered on 11 Jan 2010, 09:27 AM
Hello Alex,

Yes, thank you - this will really help us get to the problem quickly.

Greetings,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alex
Top achievements
Rank 1
answered on 13 Jan 2010, 06:43 AM
Hi Miroslav ,

Your clue with the initial generated expanded node fixed the problem.

Thanks for the help...

Best Regards,
Alexander
Tags
TreeView
Asked by
Alex
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Alex
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or