Completed
Last Updated: 20 Oct 2014 14:20 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 06 Aug 2014 11:35
Category: TreeView
Type: Bug Report
0
FIX. RadTreeView - incorrect control size when the AutoSize property is set to true and the Nodes collection is cleared
To reproduce: 
1.Add a RadTreeView and four RadButton controls.
2.Use the following code snippet:

private Random random = new Random();

public Form1()
{
    InitializeComponent();

    radTreeView1.AutoSize = true;
    radTreeView1.TreeViewElement.HorizontalScrollState = ScrollState.AlwaysHide ;
    radTreeView1.TreeViewElement.DrawBorder = false;
}

private string NextText()
{
    char[] letters = new char[random.Next(4, 11)];
    for (int i = 0; i < letters.Length; ++i)
    {
        letters[i] = (char)random.Next('a', 'z' + 1);
    }
    letters[0] = char.ToUpper(letters[0]);
    return new string(letters);
}

private RadTreeNodeCollection GetRandomNodeCollection()
{
    if (radTreeView1.Nodes.Count == 0)
    {
        return radTreeView1.Nodes;
    }

    int depth = random.Next(MaxDepth(radTreeView1.Nodes));

    var source = radTreeView1.Nodes;
    while ((depth--) >= 0 && source.Count > 0)
    {
        source = source[random.Next(source.Count)].Nodes;
    }

    return source;
}

private static int MaxDepth(RadTreeNodeCollection nodes, int currentDepth = 0)
{
    if (nodes.Count == 0)
    {
        return currentDepth;
    }

    int max = -1;

    foreach (var n in nodes)
    {
        max = Math.Max(MaxDepth(n.Nodes, currentDepth + 1), max);
    }

    return max;
}

private void UpdateTree(bool clearNodes)
{
    radTreeView1.BeginUpdate();
    if (clearNodes)
    {
        radTreeView1.Nodes.Clear();   
    }
    else
    {
        bool makeRoot = false;

        int count = random.Next(10, 50);
        for (; count > 0; --count)
        {
            makeRoot = random.NextDouble() < 0.23456789;
            var nodes = makeRoot
                        ? radTreeView1.Nodes
                        : GetRandomNodeCollection();
            
            nodes.Add(NextText());
        }
    }
    radTreeView1.EndUpdate();
    radTreeView1.ExpandAll();
}

private void radButton1_Click(object sender, EventArgs e)
{
    UpdateTree(false);
}

private void radButton2_Click(object sender, EventArgs e)
{
    UpdateTree(true);
}

private void radButton3_Click(object sender, EventArgs e)
{
    radTreeView1.ExpandAll();
}

private void radButton4_Click(object sender, EventArgs e)
{
    radTreeView1.CollapseAll();
}


Workaround: instead of clearing nodes, remove one by one:

//radTreeView1.Nodes.Clear();
while (radTreeView1.Nodes.Count > 0)
{
    radTreeView1.Nodes.Last().Remove();
}
Attached Files:
0 comments