Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Suite Pro
  New Posts New Posts RSS Feed - treeview nodeclick
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

treeview nodeclick

 Post Reply Post Reply
Author
Message
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Topic: treeview nodeclick
    Posted: 29 December 2010 at 2:11pm
I hope that I am missing something... i am using the treeview control in conjunction with the docking pane. When the user clicks a node on the treeview a new pane is added and displayed in the docking pane manager. If the user then clicks the close form button on the docking pane the pane is destroyed and the tree node.expanded is set to false. The problem is that if the user clicks the same tree node again the nodeclick event is not fired. I have tried setting the .selecteditem property equal to nothing bnut that does not help. How can I get the node click event to fire when the same/selected node is clicked a second time?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 29 December 2010 at 9:49pm
According the the help file, that is the expected behaviour of the NodeClick event:

Quote

The standard Click event is generated when the user clicks any part of the TreeView control outside a node object. The NodeClick event is generated when the user changes selection of Tree with Mouse or Keyboard. If the user's click an already selected Node it won??t be fired.



Here's a possible work-around (haven't tested it fully, so please test before deploying):


Option Explicit

Private mo_LastNode As TreeViewNode

Private Sub Form_Load()
   With Me.TreeView1
      .Nodes.Add , , , "Test"
      .Nodes.Add , , , "Test2"
   End With
End Sub

Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
   Dim lo_HitNode As TreeViewNode
  
   If Me.TreeView1.SelectedItem Is Nothing Then
      Set mo_LastNode = Nothing
      Exit Sub
   End If
  
   Set lo_HitNode = Me.TreeView1.HitTest(x, y)
   If lo_HitNode Is Nothing Then
      Exit Sub
   End If
  
   If Not lo_HitNode Is Me.TreeView1.SelectedItem Then
      Exit Sub
   End If
     
   If Me.TreeView1.SelectedItem Is mo_LastNode Then
      TreeView1_NodeClick Me.TreeView1.SelectedItem
   End If
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As XtremeSuiteControls.TreeViewNode)
   Set mo_LastNode = Node
  
   Debug.Print Node.Text & Timer
End Sub

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 8:13am
Thanks JPBro... yes, I saw from the documentation that that was the expected behaviour. I'll try the code you posted to see if that works for me. On a related issued I notice that when I click a node (other than the first node) that the nodeclick event fires twice... once for the first node on the tree and a second time for the node that I click. I see that this is also the "expected" behaviour but it makes no sense to me that the control works likes that. I saw a suggestion in another thread on this same issue that suggested using a "dummy" node as the first node but this really does not solve the problem as, from what I can tell, there is no way to make a node invisible. Any (better) idea about how to deal with this issue?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 8:56am
I haven't been able to reproduce the problem of the NodeClick event firing for the first item when you click a second item, do you have a sample project that demonstrates this?

One thing I have seen is that the NodeClick property fires for the first item when you start the program (even though the user hasn't clicked anything yet). If this is a problem, you can prevent it like this:


Option Explicit

Private mo_LastNode As TreeViewNode

Private Sub Form_Load()
   With Me.TreeView1
      .Nodes.Add , , , "Test"
      .Nodes.Add , , , "Test2"
   End With
End Sub

Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
   Dim lo_HitNode As TreeViewNode
  
   If Me.TreeView1.SelectedItem Is Nothing Then
      Set mo_LastNode = Nothing
      Exit Sub
   End If
  
   Set lo_HitNode = Me.TreeView1.HitTest(x, y)
   If lo_HitNode Is Nothing Then
      Exit Sub
   End If
  
   If Not lo_HitNode Is Me.TreeView1.SelectedItem Then
      Exit Sub
   End If
     
   If Me.TreeView1.SelectedItem Is mo_LastNode Then
      TreeView1_NodeClick Me.TreeView1.SelectedItem
   End If
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As XtremeSuiteControls.TreeViewNode)
   Static s_FiredOnce As Boolean
  
   Set mo_LastNode = Node
     
   If Not s_FiredOnce Then
      ' Skip the initial NodeClick event of the first item in the TreeView
      s_FiredOnce = True
      Exit Sub
   End If
  
  
   ' Put code to perform desired NodeClick actions below
   Debug.Print Node.Text & " " & Timer
End Sub


Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 9:44am
Yes, I have the same problem with the node_click event firing when the form is first loaded.
 
Here is a post from AAron that deals with the other issue I posted:
 
Originally posted by Aaron Aaron wrote:

Hi,
 
There nothing wrong with your code. The Node.Index is long but that won't make a difference.
 
Only:
When you click the treeview it will get the focus and a treeview item will be selected > NodeClick event will fire.
 
If you would click the second node (when the treeview hasn't got the focus yet) the treeview gets the focus and first node will be selected (Nodeclick event fires and frm1 will be loaded) after this the click on node 2 or 3 will trigger another NodeClick event.
 
Try to add a dummy node first (this will have index 1) and change the cases in the NodeClick event and try again or run in debug mode you can see what I explained.
 
 
 
 
I'll have to say that I'm really dissapointed in the behavior of the TreeView control. These couple of issues and the related work arounds are very frustrating... I may be forced to go back to the standard MS TreeView control as I did not have these problems. Any idea if these have been address in a newer release? I am currently on 13.2.1.
 
Thanks again for your feedback
Back to Top
Aaron View Drop Down
Senior Member
Senior Member
Avatar

Joined: 29 January 2008
Status: Offline
Points: 2192
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 10:35am
Originally posted by johnp johnp wrote:

Yes, I have the same problem with the node_click event firing when the form is first loaded.
 
[...] 
I'll have to say that I'm really dissapointed in the behavior of the TreeView control. These couple of issues and the related work arounds are very frustrating... I may be forced to go back to the standard MS TreeView control as I did not have these problems. Any idea if these have been address in a newer release? I am currently on 13.2.1.
 
Thanks again for your feedback
 
Hi,
 
That's the reason I stick with MS controls. I once asked a list of differences between MS and CJ controls but never got a reply. I really would like to use the CJ controls but I don't want to wait for some "strange" behavior to occure and don't have a solution. I prefer one library but it's to risky...
 
Good luck Wink
 
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 10:38am
Glad to help - I'm not sure if anything has changed with the TreeView in the latest versions (I don't actually use it for anything myself). If you open a support ticket with CodeJock at https://support.codejock.com then you might be able to get your issues resolved.

In the meantime, I've put together a little re-usable class that will fire it's own NodeClicked event as follows:

1) NOT at application start
2) Anytime a Node is clicked (even if it was previously selected).

I haven't been able to get it to fire erroneously yet, but I've only tested it for the most obvious use cases - your project may present scenarios that cause it to behave undesirably.

Here's the demo:
uploads/2676/TreeViewNodeClickMod.zip
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 10:40am
Originally posted by Aaron Aaron wrote:

Originally posted by johnp johnp wrote:

Yes, I have the same problem with the node_click event firing when the form is first loaded.
 
[...] 
I'll have to say that I'm really dissapointed in the behavior of the TreeView control. These couple of issues and the related work arounds are very frustrating... I may be forced to go back to the standard MS TreeView control as I did not have these problems. Any idea if these have been address in a newer release? I am currently on 13.2.1.
 
Thanks again for your feedback
 
Hi,
 
That's the reason I stick with MS controls. I once asked a list of differences between MS and CJ controls but never got a reply. I really would like to use the CJ controls but I don't want to wait for some "strange" behavior to occure and don't have a solution. I prefer one library but it's to risky...
 
Good luck Wink
 
Thanks Aaron... it's really too bad because most of the codejock stuff works really well.
Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 10:41am
Thanks jpbro... I'll have a look at your code.
Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 30 December 2010 at 2:14pm
jpbro, thanks again for the code... it seems to have resolved the issues that I originally found. Now, it seems that there is one last issue that I can't seem to figure out. When I click a node for the first time i set the nodes expanded property = true. The next time I click the node, the program should see that the node was expanded and perform some different action from the first time the node was clicked (e.g., close a docking pane). For some reason, the expanded property for the node is always equal to false... any ideas on this would be greatly appreciated.
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 31 December 2010 at 1:20pm
I've tried getting the Expanded property to report its value incorrectly without luck. Maybe it was fixed?

If you could modify my sample and provide steps to demonstrate the problem, I will try it here and see if the problem still exists (and if so, see if I can find a workaround).

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 31 December 2010 at 3:02pm
Thanks, let me play with it some more over the weekend before tying up more of your time. Have a happy and safe New Year!
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 31 December 2010 at 3:09pm
Sure thing - and a safe and happy new year to you too!
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2011 at 9:38am
Okay, I update my controls to 13.4.2 (I was on 13.2.1) and still cannot seem to get the expanded property to work. Here is the change that I made to your code:
 

Private Sub mo_NodeClickMod_NodeClicked(Node As XtremeSuiteControls.TreeViewNode)
   ' Instead of using the forms TreeView1_NodeClicked event,
   ' We use our modified handlers NodeClicked event
   ' The modified handlers NodeClick event doesn't fire on startup,
   ' and fires even if the already selected node is clicked again.
  
   Debug.Print "NODE CLICKED: " & Node.Text & ", Index: " & Node.Index & " @ " & Timer & " " & Node.Expanded
  
   Node.Expanded = Not (Node.Expanded)
  
End Sub
 
The Node.Expanded property is always shown as false everytime I click a node. Is it possible that the expanded property does not "work" if there are no child nodes?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2011 at 9:48am
Strange - I'm not sure what is going on on your end.

I used your code and added a Debug.Print "Expanded: " & Node.Expanded line, and when I click the parent node a few times, it expands and shrinks as expected for me*

Here's my debug output:

NODE CLICKED: Test, Index: 1 @ 35087.41
Expanded: False
NODE CLICKED: Test, Index: 1 @ 35088.11
Expanded: True
NODE CLICKED: Test, Index: 1 @ 35088.93
Expanded: False
NODE CLICKED: Test, Index: 1 @ 35089.61
Expanded: True
NODE CLICKED: Test, Index: 1 @ 35090.29
Expanded: False
NODE CLICKED: Test, Index: 1 @ 35090.95
Expanded: True
NODE CLICKED: Test, Index: 1 @ 35091.86
Expanded: False


* I notice that when double-clicking the parent node, it expands and shrinks, so each click in the double-click is counted. I will have to come up with a workaround for this.


Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2011 at 10:01am
That's strange... I had added the node.expanded value to the end of the existing debug statement and was seeing the expanded value always equal to false. I did find that if I added a child node to the 'Test' node that the expanded property was changing each time I clicked the 'Test' node. I do not think that I made any changes to your sample project... were nodes 'Test2' - 'Test4' child nodes in your sample (they are parent nodes, without children in the sample code that I have)?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1355
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2011 at 10:38am
Okay, I think I see where I misunderstood now - the Expanded property is working for you when a Node has Child Nodes, but not if the Node has no child nodes.

The documentation doesn't mention whether or not this is the expected behaviour, but to me it makes sense - How can a Node be expanded when there is nothing under it to expand? Nodes also don't show the +/- icon when there are no children, so there is no visual confusion either.

You have a couple of other options though - if you aren't using Checkboxes in your TreeView, you could substitute the Node.Checked property for the Node.Expanded property. Alternately, if you aren't using the Node.Tag property, you could use it for the same purpose.


Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
johnp View Drop Down
Groupie
Groupie
Avatar

Joined: 21 February 2008
Status: Offline
Points: 49
Post Options Post Options   Thanks (0) Thanks(0)   Quote johnp Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2011 at 10:58am
I understand the logic of what you're saying but, I believe that the behaviour of the MS treeview is different (i.e., expanded can equal true even when no child nodes exist). I appreciate your time on this and will rewrite my code so that it works without using the expanded property.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.