Solved

TreeView Problem

Posted on 1998-12-10
15
235 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
0
Comment
Question by:dekoay
  • 6
  • 6
  • 3
15 Comments
 
LVL 7

Accepted Solution

by:
Inteqam earned 50 total points
Comment Utility
try to save the key of the node you press on , like this:

'Try to add a treeview and a commanbutton to a form , and paste 'this code into , and tell me if it is what you want or not.

Private key As String
Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim n As Node

Set n = Me.TreeView1.Nodes.Add(, , "a1", "Parent1")
Set n = Me.TreeView1.Nodes.Add(, , "a2", "Parent2")
Set n = Me.TreeView1.Nodes.Add("a1", tvwChild, "b11", "child1 for Parent1")
Set n = Me.TreeView1.Nodes.Add("a1", tvwChild, "b12", "child2 for Parent1")
Set n = Me.TreeView1.Nodes.Add("a1", tvwChild, "b13", "child3 for Parent1")
Set n = Me.TreeView1.Nodes.Add("a2", tvwChild, "b21", "child1 for Parent2")
Set n = Me.TreeView1.Nodes.Add("a2", tvwChild, "b22", "child2 for Parent2")
Set n = Me.TreeView1.Nodes.Add("a2", tvwChild, "b23", "child3 for Parent2")

End Sub
Private Sub TreeView1_Click()
    Dim f As Integer
    key = TreeView1.SelectedItem.key
    f = MsgBox("want to see childs?", vbYesNo)
    If f = vbYes Then
        'call your function , which jumps to another place.
    Else
        TreeView1.SelectedItem.key = key
        TreeView1.SelectedItem.Expanded = False
    End If
End Sub

0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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


0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
BTW: Inteqam code seems to have the same problem.

0
 

Author Comment

by:dekoay
Comment Utility
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
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Yes, that's right. I know how to solve that just increase the points.
0
 

Author Comment

by:dekoay
Comment Utility
Hello Mirkwood,

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


Derrick
0
 

Author Comment

by:dekoay
Comment Utility
Hello Mirkwood,

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


Derrick
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Expert Comment

by:Inteqam
Comment Utility
well , thank you
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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




0
 

Author Comment

by:dekoay
Comment Utility
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
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Where did you leave my timer??????????????????????

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

Expert Comment

by:Mirkwood
Comment Utility
Unsubscribing
0
 
LVL 7

Expert Comment

by:Inteqam
Comment Utility
can you explain the problem in my code more ,
may be i can help you

0
 

Author Comment

by:dekoay
Comment Utility
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
0
 

Author Comment

by:dekoay
Comment Utility
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now