By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Treeview doubleclick help

P: n/a
I'm trying to implement a fairly simple Treeview procedure but running
into problems.

My Treeview has just two levels of nodes: top-level and one child
level. I want a doube-click on the Treeview to do one of two things:

If the double-click was on a top-level node then the default action of
exapnding/collapsing the node should be allowed as usual and with no
further action.

If the double-click was on a child-node then I want to be able to pick
up the text of the child item that was clicked (ie the selected item).

(And if the double-click was on neither then just ignore)

The problem is how best to distinguish between the top- and
child-level clicks.

I'm obviously looking to place some code in the Treeview's doubleclick
event but the eventargs of this event don't AFAICS return anything
useful.

Any pointers much appreciated.

JGD
Oct 31 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You can include a key for each node, which can be any string you
choose. I did this in a project, which looked something like this:
level-name-creationdate-uniqueid

so every one was unique ( it is a key ). You can configure this however
suits you.

Tom

John Dann wrote:
>I'm trying to implement a fairly simple Treeview procedure but running
into problems.

My Treeview has just two levels of nodes: top-level and one child
level. I want a doube-click on the Treeview to do one of two things:

If the double-click was on a top-level node then the default action of
exapnding/collapsing the node should be allowed as usual and with no
further action.

If the double-click was on a child-node then I want to be able to pick
up the text of the child item that was clicked (ie the selected item).

(And if the double-click was on neither then just ignore)

The problem is how best to distinguish between the top- and
child-level clicks.

I'm obviously looking to place some code in the Treeview's doubleclick
event but the eventargs of this event don't AFAICS return anything
useful.

Any pointers much appreciated.

JGD

Oct 31 '06 #2

P: n/a
You could also maintain a collection that would contain just the root
nodes (add them to the collection when you populate the treeview
nodes). Then you can do a quick if RootNodeCollection.Contains(...)
test.

Just my 2 cents

Thanks,

Seth Rowe
John Dann wrote:
I'm trying to implement a fairly simple Treeview procedure but running
into problems.

My Treeview has just two levels of nodes: top-level and one child
level. I want a doube-click on the Treeview to do one of two things:

If the double-click was on a top-level node then the default action of
exapnding/collapsing the node should be allowed as usual and with no
further action.

If the double-click was on a child-node then I want to be able to pick
up the text of the child item that was clicked (ie the selected item).

(And if the double-click was on neither then just ignore)

The problem is how best to distinguish between the top- and
child-level clicks.

I'm obviously looking to place some code in the Treeview's doubleclick
event but the eventargs of this event don't AFAICS return anything
useful.

Any pointers much appreciated.

JGD
Oct 31 '06 #3

P: n/a
In the click event, you can check to see if the node passed to the event has
a parent or not...if not, then it's not a child node.
--
Dennis in Houston
"John Dann" wrote:
I'm trying to implement a fairly simple Treeview procedure but running
into problems.

My Treeview has just two levels of nodes: top-level and one child
level. I want a doube-click on the Treeview to do one of two things:

If the double-click was on a top-level node then the default action of
exapnding/collapsing the node should be allowed as usual and with no
further action.

If the double-click was on a child-node then I want to be able to pick
up the text of the child item that was clicked (ie the selected item).

(And if the double-click was on neither then just ignore)

The problem is how best to distinguish between the top- and
child-level clicks.

I'm obviously looking to place some code in the Treeview's doubleclick
event but the eventargs of this event don't AFAICS return anything
useful.

Any pointers much appreciated.

JGD
Nov 1 '06 #4

P: n/a
John Dann wrote:
I'm trying to implement a fairly simple Treeview procedure but running
into problems. My Treeview has just two levels of nodes: top-level
and one child level.

The problem is how best to distinguish between the top- and
child-level clicks.
Root nodes don't have a Parent whereas Child nodes do.

Check the TreeView's SelectedNode property and then whether or not it's
Parent property has any value.

Sub tv_DoubleClick( ... ) Handles tv.DoubleClick
If Not ( tv.SelectedNode Is Nothing ) Then
If tv.SelectedNode.Parent Is Nothing Then
' Root Node
Else
' Child Node (somewhere down the tree)
End If
Else
' Nothing at all selected
End If
End Sub

You /might/ also need to put code into the MouseUp event to ensure that
there is an item selected when the double-click event arrives. I can't
remember if this happens automatically or not, but I've had to do this
for context menus, so I thought I'd better throw it in :

Sub tv_MouseUp( ... ) Handles tv.MouseUp
Dim node as TreeNode _
tv.GetNodeAt( e.X, e.Y )

If Not ( node Is Nothing ) Then
tv.SelectedNode = node
End If
End Sub

If you take this model further, so that different nodes can perform
different "actions", then you might consider adding customised TreeNodes
to the Treeview and adding code into methods on these custom Treenodes,
something like :

Class BeepingNode
Inherits TreeNode

Public Sub New()
MyBase.New()
End Sub

Public Sub Beep()
Beep()
End Sub

End Class

Then

Sub tv_AfterSelect( ... ) Handles tv.AfterSelect
If TypeOf e.Node Is BeepingNode Then
DirectCast( e.Node, BeepingNode ).Beep()
End If
End Sub

HTH,
Phill W.

Nov 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.