473,503 Members | 6,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Treeview doubleclick help

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
4 6356
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1841
by: Vibor | last post by:
Hello, I have XML file that looks likes this: <?xml version="1.0" encoding="utf-8" ?> <prezentacije> <datoteka naziv="Koherentni valovi"...
7
8390
by: (Pete Cresswell) | last post by:
I've got KeyDown coding and it fires when other keys are pressed, but when Enter is pressed, nothing. I'd like to support the (standard?) Windows behavior of executing DblClick processing when...
0
1811
by: Sonia Igla | last post by:
Hi. I need to perform DBLCLK on TreeView Node. I try the following: private static extern int SendMessage(IntPtr hWnd, uint msg, UInt32 wParam, UInt32 lParam); private const UInt32...
2
2412
by: Sonia Igla | last post by:
Hi. I need to perform DBLCLK on TreeView Node. I try the following: private static extern int SendMessage(IntPtr hWnd, uint msg, UInt32 wParam, UInt32 lParam); private const UInt32...
3
821
by: feel | last post by:
Goin' crazy with this recursive function ported from delphi... I send a string like DirA/ DirB /DirC but i get in the treeView each one in a new node.Cant get the child node....!! -DirA -DirB...
1
10735
by: JustinG | last post by:
I am relativley new to C#, and I am trying to write code using the compact framework, that will allow a handheld user to hit enter while a treeview node is selected, which will then do something...
4
1596
by: shoa | last post by:
Hello I have a TreeView in my Window application. In that I have some nodes (parent nodes), each parent node has some children. What I want is that when I double click a node (either parent or...
3
8256
by: C Glenn | last post by:
I would like one DoubleClick event handler to handle all double clicks throughout a DataGrid. I've assigned a DoubleClick event handler to the DataGrid and it works nifty-spiffy so long as I click...
5
1361
by: monski | last post by:
i want to search a record using a treeview control. pls help. thanks
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.