472,993 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

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 6334
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
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
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
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
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
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
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
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
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
by: monski | last post by:
i want to search a record using a treeview control. pls help. thanks
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.