TreeView node...

T

Tim

Hi

I have a form with a treeview on it. When I select a particular node it
adds/shows a tab on the form. The treeview node remains selected as it
should. The user can close the tab or remove the focus to another tab.

Clicking on the same already selected node should add/show the tab, however
the after select event does not fire as the node is already selected. I
trapped the click event of the treeview but that is not node specific. In
the code I have a variable to remember the current node.

When I fire the click event it works great if the user clicks on the same
node, if they click on another node I have no way of telling as the click
event happens before the after select.

So if the user clicks NodeA it opens tab. NodeA is retained in memory as
current node. If the user closes the tab and then clicks on NodeA again it
works great because NodeA is in a variable. But if the user clicks NodeB
then the tab for NodeA opens because NodeA is the current node and the click
event happens before the after select event which will then fire the code
for NodeB.

How can I solve this issue?

Tim
 
G

Guest

While the Click event does not provide you with an EventArg that specifies
the currently selected node... the TreeView itself will tell you... When the
Click event fires, check the SelectedNode property of the TreeView to
determine which node is currently selected.

Brendan
 
G

Guest

I apologize, I misread some of what you said before replying... Click doesn’t
always occur after BeforeSelect or AfterSelect.

Brendan
 
D

Danny Tuppeny

Tim said:
I have a form with a treeview on it. When I select a particular node it
adds/shows a tab on the form. The treeview node remains selected as it
should. The user can close the tab or remove the focus to another tab.

Clicking on the same already selected node should add/show the tab,
however the after select event does not fire as the node is already
selected. I trapped the click event of the treeview but that is not node
specific. In the code I have a variable to remember the current node.

When I fire the click event it works great if the user clicks on the same
node, if they click on another node I have no way of telling as the click
event happens before the after select.

So if the user clicks NodeA it opens tab. NodeA is retained in memory as
current node. If the user closes the tab and then clicks on NodeA again it
works great because NodeA is in a variable. But if the user clicks NodeB
then the tab for NodeA opens because NodeA is the current node and the
click event happens before the after select event which will then fire the
code for NodeB.

How can I solve this issue?

What's about the SelectedNode property on the tree?
 
G

Guest

That was my thought earlier as well... only I was sadly mistaken.

The trick with SelectedNode is knowing when to check it... and doing so on
the Click event does not always yield the desired outcome as order of the
events is Click, BeforeSelect and AfterSelect. This is problematic for him
because SelectedNode is changed between BeforeSelect and AfterSelect.

Brendan
 
J

JohnAtAphelion

Assuming tvChild is your TreeView control,

private void tvChild_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
tnClickedOn = tvChild.GetNodeAt(e.X, e.Y);
}

Thus tnClickedOn will always be the last node that the user clicked
on... Of course, you will need to define tnClickedOn in a scope such
that it will be visible to everything that needs to use it.

Hope this helps,

JB
 
J

JohnAtAphelion

Assuming tvChild is your TreeView control,

private void tvChild_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
tnClickedOn = tvChild.GetNodeAt(e.X, e.Y);
}

Thus tnClickedOn will always be the last node that the user clicked
on... Of course, you will need to define tnClickedOn in a scope such
that it will be visible to everything that needs to use it.

Hope this helps,

JB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top