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

RadTreeView FindNodeByValue StackOverFlow Repro

5 Answers 235 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Meaning Of Lights
Top achievements
Rank 2
Meaning Of Lights asked on 10 Nov 2008, 03:46 AM
Hi ,

Here is a repro for a bug, I dont think its the same as the one mentioned here: http://www.telerik.com/community/forums/aspnet-ajax/treeview/stack-overflow-on-nodeclick-after-serversidecallback.aspx



The FindNodeByValue method produces a Stack Overflow. I need a fix from Telerix as the Call Stack is inside the FindNodeByValue method and I cant see this without the pdb files, let alone change the source code...

        protected void Button1_Click(object sender, EventArgs e)
        {

            RadTreeView1.Nodes.Clear();
            RadTreeNode tn = new RadTreeNode();
            RadTreeNode childNode = null;

            Random rnd = new Random();
            for (int i = 1; i < 2000; i++)
            {
                tn = new RadTreeNode();
                tn.Text = i.ToString();
                tn.Value = i.ToString();
                RadTreeView1.Nodes.Add(tn);

            }


//for this repro, I put this loop below, however in my application it is nested in the above loop.
            for (int i = 1; i < 2000; i++)
            {

                childNode = RadTreeView1.FindNodeByValue(Convert.ToUInt32((rnd.NextDouble() -.001) * i).ToString());
                tn.Text = i.ToString();
                tn.Value = i.ToString();
                childNode.Nodes.Add(tn);   
            }






To avoid the StackOverflow I was hoping to bind the treeview to a datasource, eg:

OleDbConnection dbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/Tree.mdb"));
                dbCon.Open();

OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Links", dbCon);
DataSet ds = new DataSet();
adapter.Fill(ds);

RadTreeView1.DataFieldID = "NODEID";
RadTreeView1.DataFieldParentID = "PARENTID";
RadTreeView1.DataTextField = "TEXT";


However this project requires a TreeView with roughly 3600 nodes and some branches are 6 levels deep.. I cant bind since the Child and Parent IDs are NON-Unique:

1818    1819
1818    1886
1819    1820
1819    1847
1819    1875
1820    1846
1820    1821
1820    1833
1821    1831
1821    1826
1821    1827



Looking forward to your response, thanks

Jeremy






5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 10 Nov 2008, 07:59 AM
Hi Jeremy,

Since FindNodeByValue is a recursive method calling it 2000 times in the same method can eat up the stack hence the problem. What is your realistic scenario which reproduces the problem? How do you populate the treeview in your real-life case?

Regards,
Atanas Korchev,
the Telerik dev team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meaning Of Lights
Top achievements
Rank 2
answered on 10 Nov 2008, 11:11 AM
Hi Atanas,
Tomorrow at work I'll put together a more accurate sample to reproduce the problem, I think we are opting for  "On Demand Load" however it'd be good to solve this.

Does the FindNodeByValue method have an optimisation that returns the "Node By Value" without releasing the stack? It seems the method may have a ref datatype with a root reference.

I'll get back to you with a sample, if I have time at work, I'll report back either way. If you nest the two loops I showed in the first thread, thats what I'll end up showing you:

            for (int i = 1; i < 500; i++)
            {
                tn = new RadTreeNode();
                tn.Text = i.ToString();
                tn.Value = i.ToString();
                RadTreeView1.Nodes.Add(tn);



 
                 for (int j = 1; j < 500; j++)
                 {
                  int indexOfNodeInTree = xyz;
                   childNode = RadTreeView1.FindNodeByValue(indexOfNodeInTree).ToString());
                    tn = new RadTreeNode();
                    tn.Text = j.ToString();
                    childNode.Nodes.Add(tn);   


Thanks Atanas, cheers Jeremy T

<edit>
 I think the 6 levels deep exacerbates the problem, I'll try replacing the 500 with several levels of recursion
</edit>

0
Meaning Of Lights
Top achievements
Rank 2
answered on 10 Nov 2008, 10:09 PM
Hi,

The datatable dtCodes contains 3651 records with Child/Parent IDs and Child/Parent Names. If you need the dtCodes table as a csv file just let me know.

DataTable dtCodes = Helper.ConfigurationHelper.GetCodes();

            foreach (DataRow dr in dtCodes.Rows)
            {
                if (dr["ChildID"] == DBNull.Value)
                {
                    RadTreeNode tn = new RadTreeNode(dr["ParentID"].ToString(), dr["ParentName"].ToString());
                    RadTreeView1.Nodes.Add(tn);
                    tn.Checked = true;
                }
                else
                {

                    RadTreeNode parent =  RadTreeView1.FindNodeByValue(dr["ParentID"].ToString());
                    if (parent == null)
                    {
                        parent = new RadTreeNode(dr["ParentCode"].ToString(), dr["ParentID"].ToString());
                        RadTreeView1.Nodes.Add(parent);
                        parent.Checked = true;
                    }
                    RadTreeNode child =  RadTreeView1.FindNodeByValue(dr["ChildID"].ToString());
                    if (child == null)
                    {
                        child = new RadTreeNode(dr["ChildName"].ToString(), dr["ChildID"].ToString());
                        child.Checked = true;
                    }
                    else
                    {
                        RadTreeView1.Nodes.Remove(child);
                    }
                    parent.Nodes.Add(child);
                }
            }


<edit>
I just followed these articles and the "load on demand" method works well, I'll have to tweak a fiar few things but it looks to be our savour:

http://demos.telerik.com/aspnet/prometheus/TreeView/Examples/Programming/WebService/DefaultCS.aspx and more importantly: http://blogs.telerik.com/AtanasKorchev/Posts/08-08-06/Performance_Tip_Use_Web_Service_Load_On_Demand_with_RadTreeView.aspx

I'll be happy to provide infomation if you wish to troubleshoot the reported bug
</edit>


Thanks again Jeremy T
0
Atanas Korchev
Telerik team
answered on 11 Nov 2008, 11:40 AM
Hi Jeremy,

I couldn't reproduce the stackoverflow exception using your code. However I have converted the FindNodeByValue method to be iterative rather than recursive. I suggest you open a support ticket and send me your csv file as an attachment. I will test the current build and let you know of the progress.

Regards,
Atanas Korchev,
the Telerik dev team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Meaning Of Lights
Top achievements
Rank 2
answered on 29 Dec 2008, 08:59 AM
Hi Atanas,

I've overcome the problem and will edit this post with a "bare bone/cut down" example.. Next week.

IE is really slow at processing TreeView Javascript with recursive routines. I'm happy to hear you re-mastered the function:) Awesome!

I'll get back to everyone with a example to demo how I dealt with rendering such huge TreeViews... as per your blog.. the only WTG is on-demand!!

Thanks kindly,

Jeremy Lecky-Thompson

Tags
TreeView
Asked by
Meaning Of Lights
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Meaning Of Lights
Top achievements
Rank 2
Share this question
or