Home - Forums-.NET - FlyTreeView (ASP.NET) - New version generates error on existing code

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

New version generates error on existing code
Link Posted: 21-Jan-2008 05:11
Hi,

First of all, I would like to complement you on your great support!! Allways fast and reliable answers.  

I populate my flytreeview on demand and use this functionality to store the state of the tree:

        if (!String.IsNullOrEmpty(PATH))
        {
            FlyTreeNodeCollection nodes = MainTree.Nodes;
            FlyTreeNodeCollection sn;

            string[] values = PATH.Split('-');
            string lastNode = values[values.Length - 1];

            foreach (string s in values)
            {
                sn = nodes.FindByValue(s, false);

                foreach (FlyTreeNode ftn in sn)
                {
                    ftn.Expanded = true;
                    MainTree.PopulateExpandedNodes();
                    nodes = ftn.ChildNodes;

                    if (String.Equals(s, lastNode))
                    {
                        ftn.Selected = true;
                    }
                }
            }
        }

This has worked fine but when I changed the FlyTreeView.dll file to your latest version(4.3.1.222) I get an error:
"Cannot implicitly convert type 'NineRays.WebControls.FlyTreeNode' to 'NineRays.WebControls.FlyTreeNodeCollection'"

This is the row that isn't working anymore: "sn = nodes.FindByValue(s, false);"
Is this a bug or is it something I have done wrong?

BR
Link Posted: 21-Jan-2008 05:17
[quote="porsche"]
sn = nodes.FindByValue(s, false);

To fix the issue replace FindByValue with FindAllByValue.
There was an issue with FindXXX methods of the treeview.
So to handle it we had to change return type of FindByValue and to introduce the additional FindAllByValue method.
Please use it in place of FindByValue (this one returns the first found occurrence).
Link Posted: 21-Jan-2008 22:19
When I use the FindAllByValue method I get a strange error. When I reload the page the tree expands correctly, but when I expand another node, all subnodes are printed twice.
Link Posted: 21-Jan-2008 22:23
How do I replicate the issue?

Can you give me some code that I can run against treeview?
Link Posted: 03-Feb-2008 21:52
Hi

The first time the tree is printed this is what the tree looks like:
-Administration
  - Database
  - Documents
  - Users

And after reload the tree looks like this:
-Administration
  - Database
  - Documents
  - Users
  - Database
  - Documents
  - Users

Here is a sample of the code:

protected void MainTree_OnPopulateNodes(object sender, FlyTreeNodeEventArgs e)
    {
        DataSet ds = null;

        switch (e.Node.Level)
        {
            case 0:
                if (String.Equals(e.Node.Text, PLATFORMS, StringComparison.OrdinalIgnoreCase))
                {
                    ds = DatabaseFunctions.TreeGetPlatforms();
                    Level1_PlatformNodes(ds, e.Node.ChildNodes);
                }
                else
                {
                    Level1_AdministrationNodes(e.Node.ChildNodes);
                }
                break;
            case 1:
                if (String.Equals(e.Node.Text, ADMINISTRATION_USERS, StringComparison.OrdinalIgnoreCase))
        {
          Level2_AdministrationUserNodes(e.Node.ChildNodes, e.Node);
        }
        else if (String.Equals(e.Node.Text, ADMINISTRATION_DOCUMENTS, StringComparison.OrdinalIgnoreCase))
        {
          Level2_AdministrationDocumentNodes(e.Node.ChildNodes, e.Node);
        }
        else if (String.Equals(e.Node.Text, ADMINISTRATION_DATABASE, StringComparison.OrdinalIgnoreCase))
        {
          Level2_AdministrationDatabaseNodes(e.Node.ChildNodes, e.Node);
        }
                break;
        }
    }

private void Level1_AdministrationNodes(FlyTreeNodeCollection nodes)
{
  FlyTreeNode ftn = CreateNode(
    ADMINISTRATION_DATABASE,
    "A",
    ADMINISTRATION_DATABASE,
    null,
    null,
    null,
    true,
    false,
    false
    );

  nodes.Add(ftn);

  ftn = CreateNode(
    ADMINISTRATION_DOCUMENTS,
    "B",
    ADMINISTRATION_DOCUMENTS,
    null,
    null,
    null,
    true,
    false,
    false
    );

  nodes.Add(ftn);

  ftn = CreateNode(
    ADMINISTRATION_USERS,
    "C",
    ADMINISTRATION_USERS,
    null,
    null,
    null,
    true,
    false,
    false
    );

  nodes.Add(ftn);
}
Link Posted: 04-Feb-2008 00:32
Thanks for the code. Your code does not seem to contain anything criminal.

Is it possible to get a simple ASPX page with the only treeview, without external references, so I can run and debug it locally? This is a 100% way to fix any possible issues.

Thanks in advance.
Link Posted: 04-Feb-2008 04:37
Here is a simple example that generates the same error. If you just expand all the nodes in the tree, everything works perfect. But when you click on the link under "Sub Node 2:1", the tree is reloaded and the subnode for "Sub Node 2:2" is printed twice. //Default2.aspx [code] Untitled Page function onSelectedNodeChangedHandler(sender, oldNode, node) { changeNavUrl(node); } function changeNavUrl(node) { var navUrl; navUrl = node.getNavigateUrl(); node.setNavigateUrl(navUrl); } function onNodeEventHandler(sender, node, eventType) { if(eventType == "collapsed" && node.getNavigateUrl() != null) { changeNavUrl(node); } }
test
[/code] //And the Default2.aspx.cs [code]using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using NineRays.WebControls; public partial class Default2 : System.Web.UI.Page { private string PATH; protected void Page_Load(object sender, EventArgs e) { PATH = (Request.QueryString["path"] == null) ? null : Request.QueryString["path"].ToString(); if (!Page.IsPostBack) { InitializeTree(); } if (!String.IsNullOrEmpty(PATH)) { FlyTreeNodeCollection nodes = MainTree.Nodes; FlyTreeNodeCollection sn; string[] values = PATH.Split('/'); string lastNode = values[values.Length - 1]; foreach (string s in values) { sn = nodes.FindAllByValue(s, false); foreach (FlyTreeNode ftn in sn) { ftn.Expanded = true; MainTree.PopulateExpandedNodes(); nodes = ftn.ChildNodes; if (String.Equals(s, lastNode)) { ftn.Selected = true; } } } } MainTree.FocusNode = MainTree.SelectedNode; } private void InitializeTree() { MainTree.Nodes.Add( CreateNode( "Top Node", "A", null, null, null, null, true, false, false ) ); } protected void MainTree_OnPopulateNodes(object sender, FlyTreeNodeEventArgs e) { switch (e.Node.Level) { case 0: FlyTreeNode ftn = CreateNode( "Sub Node 1", "B", null, null, null, null, true, false, false ); e.Node.ChildNodes.Add(ftn); break; case 1: ftn = CreateNode( "Sub Node 2:1", "C", null, null, null, null, true, false, false ); e.Node.ChildNodes.Add(ftn); ftn = CreateNode( "Sub Node 2:2", "D", null, null, null, null, true, false, false ); e.Node.ChildNodes.Add(ftn); break; case 2: if (String.Equals(e.Node.Value, "C", StringComparison.OrdinalIgnoreCase)) { ftn = CreateNode( "Click on this node to reload the page", "E", null, null, "Default.aspx?path=" + (e.Node.Path + "/E"), null, true, true, false ); e.Node.ChildNodes.Add(ftn); } else if (String.Equals(e.Node.Value, "D", StringComparison.OrdinalIgnoreCase)) { ftn = CreateNode( "This node is displayed twice when the page is reloaded.", "F", null, null, "Default.aspx?path=" + (e.Node.Path + "/F"), null, true, true, false ); e.Node.ChildNodes.Add(ftn); } break; } } private FlyTreeNode CreateNode(string text, string value, string toolTip, string imageUrl, string navU
Link Posted: 04-Feb-2008 05:31
Great!  

Please replace at Page_Load
if (!String.IsNullOrEmpty(PATH))

with
if (!String.IsNullOrEmpty(PATH) && !IsPostBack))


This will avoid populating of the same node from Page_Load. (Also called from callback handler).

Actually today we included an additional check for populating of the same node during callback twice.
It will be available within the next build, but this is not a fix, rather an additional check "de bene esse".

Please add an additional condition (see above code) to fix the issue.
Link Posted: 04-Feb-2008 22:36
-Super, now it works!

Once again, thanks for great support!