The
AfterSelect()
event only fires for new selections and won't fire if already selected. You may want to capture the TreeView's Click event instead.
private void treeView1_Click(object sender, EventArgs e)
{
TreeViewHitTestInfo info = treeView1.HitTest(treeView1.PointToClient(Cursor.Position));
if (info != null)
MessageBox.Show(info.Node.Text);
}
Edit:
Here is what I think that you are attempting to do:
private void treeView1_Click(object sender, EventArgs e)
{
TreeViewHitTestInfo info = treeView1.HitTest(treeView1.PointToClient(Cursor.Position));
if (info != null)
{
comboBox1.DisplayMember = "Text";
comboBox1.DataSource = info.Node.Nodes;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var node = comboBox1.SelectedItem as TreeNode;
if (node == null)
return;
treeView1.SelectedNode = node;
treeView1.Focus();
}