We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

TreeView Problem

dekoay
dekoay asked
on
Medium Priority
320 Views
Last Modified: 2013-12-26
Hello Experts,

I have a program which consists of tree view. When I click treeview, it will fire the NodeClick module and the highlight will moove from the current position to new position. However, I had made a msgbox to make sure that user confirmed wanted to goo for new node position by triggger a message box with Yes No button.
If yes, then the highlight cursor move to new position. If user select No button, how can code my program in order  move this highlight back to the previous position.

Your help will be much appreciated. Thank You
Comment
Watch Question

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
Here is the beginning of some code
Node the code is not working correctly since
  Set TreeView1.SelectedItem = prevnode
does not work in NodeClick
I know the answer to this question but not for 50 points.


Dim prevnode As Node
Dim systemmove As Boolean

Private Sub Form_Load()
    Dim i As Integer
    For i = 0 To 10
       TreeView1.Nodes.Add , , , "hello" & i
    Next
End Sub



Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    If (systemmove) Then
        Set prevnode = Node
    Else
        If (MsgBox("Are you sure you want to move to " & Node.Text, vbYesNo) = vbYes) Then
            Set prevnode = Node
        Else
            systemmove = True
            Set TreeView1.SelectedItem = prevnode
            systemmove = False
        End If
    End If
End Sub


Commented:
BTW: Inteqam code seems to have the same problem.

Author

Commented:
Hello Inteqam, MirkWood,

I am very glad and appreciate that you gave me a solution but most unfortunately the highlight cursor does not return to previous position when I selected No button. :( My main goal is to get the highlight cursor back to the previous position.

Your help will be much appreciate.

Dekoay

Commented:
Yes, that's right. I know how to solve that just increase the points.

Author

Commented:
Hello Mirkwood,

If u could provide me the solution, extra 40 points will be yours.


Derrick

Author

Commented:
Hello Mirkwood,

If u could provide me the solution, extra 40 points will be yours, provided it really works :)


Derrick

Commented:
well , thank you

Commented:
I don't understand.
Here is the answer anyway. Just to close this thread.

Switch selectednode of treeview in nodeclick

Dim prevnode As Node
Dim systemmove As Boolean

Private Sub Form_Load()
    Dim i As Integer
    For i = 0 To 10
       TreeView1.Nodes.Add , , , "hello" & i
    Next
End Sub



Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    If (systemmove) Then
        Set prevnode = Node
    Else
        If (MsgBox("Are you sure you want to move to " & Node.Text, vbYesNo) = vbYes) Then
            Set prevnode = Node
        Else
            systemmove = True
            Timer1.Enabled = True
        End If
    End If
End Sub

Private Sub Timer1_Timer()
    Timer1.Enabled = False
    Set TreeView1.SelectedItem = prevnode
    systemmove = False
End Sub




Author

Commented:
Hello MirkWood,

Thank you ver much for the answer, but still it don't work. The highlight did not return back to previous position. By the way, did u try this on VB5 ? I've tried and below is my code :

Private Sub TreeView1_NodeClick(ByVal Node As ComctlLib.Node)

Dim answer As Integer
Dim nodetext As String
Dim index As Integer

If (systemmove) Then
   Set prevnode = Node
Else
   answer = MsgBox("Ready to Move to next level ?", vbYesNo)
   If answer = vbYes Then
   Set prevnode = Node
   Else
      systemmove = True
      Set TreeView1.SelectedItem = prevnode
      systemmove = False
   End If
End If
End Sub

If possible, pls verify for me the mistakes in my code. Your help will be appreciate

Commented:
Where did you leave my timer??????????????????????

You're code does not resemble my code...
BTW: You already gave the points to somebody else......

Commented:
Unsubscribing

Commented:
can you explain the problem in my code more ,
may be i can help you

Author

Commented:
Hello Inteqam,

Your codes are fine except that the highlight/cursor does not return to the previous position I click.

Hello Mirkwood,

I didn't give any points to anyone yet. In fact I don't know how to share the points between you and Inteqam as I'm new to this experts-exchange. may be u could give me sonme advice on how I can separate points so that I could give the points to the right person. Btw, what is the use of timer, I use it at first, but i see nothing happen so I took it out.


Yurs sincerely,
Derrick Koay

Author

Commented:
Hello Inteqam,

Your codes are fine except that the highlight/cursor does not return to the previous position I click.

Hello Mirkwood,

I didn't give any points to anyone yet. In fact I don't know how to share the points between you and Inteqam as I'm new to this experts-exchange. may be u could give me sonme advice on how I can separate points so that I could give the points to the right person. Btw, what is the use of timer, I use it at first, but i see nothing happen so I took it out.


Yurs sincerely,
dekoay
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.