Solved

TreeView Problem

Posted on 1998-12-10
15
247 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
ID: 1488854
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
ID: 1488855
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
ID: 1488856
BTW: Inteqam code seems to have the same problem.

0
 

Author Comment

by:dekoay
ID: 1488857
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
ID: 1488858
Yes, that's right. I know how to solve that just increase the points.
0
 

Author Comment

by:dekoay
ID: 1488859
Hello Mirkwood,

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


Derrick
0
 

Author Comment

by:dekoay
ID: 1488860
Hello Mirkwood,

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


Derrick
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:Inteqam
ID: 1488861
well , thank you
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1488862
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
ID: 1488863
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
ID: 1488864
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
ID: 1488865
Unsubscribing
0
 
LVL 7

Expert Comment

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

0
 

Author Comment

by:dekoay
ID: 1488867
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
ID: 1488868
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

929 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

12 Experts available now in Live!

Get 1:1 Help Now