T
Tom
Hello everyone,
I found a frustrating behavior in the TreeView control in .NET 2.0.
The TreeNode that is passed in the TreeNodeMouseClickEventArgs is
incorrect when the TreeView automatically scrolls upon expanding. Here
is some code that will reproduce the problem:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
TreeNode rootnode = new TreeNode("Level 1: Node Number 1");
for (int i = 0; i < 5; i++)
{
TreeNode tempNode = new TreeNode(string.Format("Level
2: Node Number {0}", i));
for (int z = 0; z < 50; z++)
{
tempNode.Nodes.Add(new
TreeNode(string.Format("Level 3: Node Number {0}", z)));
}
rootnode.Nodes.Add(tempNode);
}
this.treeView1.Nodes.Add(rootnode);
}
private void treeView1_NodeMouseDoubleClick(object sender,
TreeNodeMouseClickEventArgs e)
{
MessageBox.Show(e.Node.Text);
}
}
}
Try double clicking on the node labeled "Level 2: Node Number 1". I
would expect that e.Node.Text would say "Level 2: Node Number 1".
However, it reads "Level 3: Node Number 1".
Is there something that I am doing wrong? Any work arounds?
Thanks,
Tom
I found a frustrating behavior in the TreeView control in .NET 2.0.
The TreeNode that is passed in the TreeNodeMouseClickEventArgs is
incorrect when the TreeView automatically scrolls upon expanding. Here
is some code that will reproduce the problem:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
TreeNode rootnode = new TreeNode("Level 1: Node Number 1");
for (int i = 0; i < 5; i++)
{
TreeNode tempNode = new TreeNode(string.Format("Level
2: Node Number {0}", i));
for (int z = 0; z < 50; z++)
{
tempNode.Nodes.Add(new
TreeNode(string.Format("Level 3: Node Number {0}", z)));
}
rootnode.Nodes.Add(tempNode);
}
this.treeView1.Nodes.Add(rootnode);
}
private void treeView1_NodeMouseDoubleClick(object sender,
TreeNodeMouseClickEventArgs e)
{
MessageBox.Show(e.Node.Text);
}
}
}
Try double clicking on the node labeled "Level 2: Node Number 1". I
would expect that e.Node.Text would say "Level 2: Node Number 1".
However, it reads "Level 3: Node Number 1".
Is there something that I am doing wrong? Any work arounds?
Thanks,
Tom