Solved

Treeview Control

Posted on 1998-09-28
10
235 Views
Last Modified: 2013-12-25
I have a question which is related to the treeview control.

I am creating an application for policies and procedures within my company.  The treeview works like this so far it is reading all of the information from a SQL database.  If someone is willing to give me some real help I would be willing to send the code to them.

Division
   |
    Department
         |
          Policy Name
               |
                Procedure Name
                     |
                      Procedure Step
                            |
                             Procedure Step Text (RichText)

What I am having trouble doing is this.  When the user selects the procedure Step, I want the text to display in a rich text box to the right of it.  That part works, but then when the user moves to another step or procedure or basically anything other than the step they are working on from the treeview, I want it to prompt them to save that step, and then move the focus to the item they have chosen.  I will start this out at 100 points, but if you can provide me with real detailed help, I will be willing to up the points a little.
0
Comment
Question by:sgroner
  • 5
  • 3
  • 2
10 Comments
 
LVL 2

Expert Comment

by:MelissaC
ID: 1487183
I think what you need is to handle the event "LostFocus",but there's only the treeview.lostfocus, not a treeview.node.lostfocus. So I think I would solve this with an event "treeview.nodeclick":
The first time a nodeclick event occurs, you store the node ID in a variable. The second time it occurs, you read the variable to know which node the user COMES FROM (the nodeclik event had a parameter that shows which node has been clicked this time, not which one was active before). Hope this solves your problem.

0
 
LVL 1

Author Comment

by:sgroner
ID: 1487184
Can you be a little more specific.  Perhaps you can throw up some code, I think that would help alot.  With a single event to handle everything, it can get confusing.  I would appreciate any code snippets you can provide.  Then I will award the point to you.  Thanks.
0
 
LVL 2

Expert Comment

by:MelissaC
ID: 1487185
Well, you've added the treeview in your form, now you can go to source-view and select treeview1 from the combo-box above the source. Then select from the combo-box beside it the "nodeclick event" and VB will generate this code for you:

Private Sub TreeView1_NodeClick(ByVal Node As ComctlLib.Node)
End Sub

Make a global variable called "PreviousNodeID" and initialize it with NULL. Use code like this:

Private Sub TreeView1_NodeClick(ByVal Node As ComctlLib.Node)
  SaveItem(PreviousItemID)  'First handle the things you
                    'wanted to do with the previously selected                     'node
  PreviousItemID=Node   'now store the current item in the                         'variable
End Sub


private sub SaveItem(Node As ComctlLib.Node)
   if not(node=NULL) then
      dowhatyouwanttodo()
   end if  
end sub


0
 
LVL 1

Author Comment

by:sgroner
ID: 1487186
Ok, i saw this the first time.  Have you tested this process.  It does not work as you would expect.  The focus does not return even if I tell it to.  I have used the following code, tell me if you think it is correct.

Private Sub tv_NodeClick(ByVal Node As MSComctlLib.Node)

    Dim Retval As Long
   
    If NeedsSaved = True Then
        Retval = MsgBox("You must first save this procedure step, do you want to do this now?", vbYesNo + vbExclamation, "Save Now?")
        Select Case Retval
            Case vbYes
                MsgBox "Would have saved " & CurrentKey & " _                       moving to " & Node.Index
                NeedsSaved = False
                Set tv.SelectedItem = tv.Nodes(Node.Index)
            Case vbNo
                MsgBox "Not being saved"
                NeedsSaved = False
                Set tv.SelectedItem = tv.Nodes(Node.Index)
        End Select
    End If

End Sub

The message box under the 'YES' answer reports the correct information but the focus does not get to the new item.  can you try this and see what you think.  It is not working for me.
0
 
LVL 1

Author Comment

by:sgroner
ID: 1487187
Damn refresh.  Sorry.  I did not see the code.  Go ahead and answer again.  I will award the points.
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 1

Author Comment

by:sgroner
ID: 1487188
One more quick question.  what type of variable should PreviewItemID be, a LONG or a NODE.


I need to check the TAG before the code in the node click.  It should only be fired if the node.tag = "ProcedureStep"

If I check the PreviousItemID.TAG Property it tells me that it is not initialized.

Any thoughts.
0
 
LVL 2

Expert Comment

by:vspeter
ID: 1487189
I think you are almost there. But there is one slight problem. Consider the answer bellow.

DO NOT place the code

    If NeedsSaved = True Then
        Retval = MsgBox("You must first save this procedure step, do you want to do this now?", vbYesNo + vbExclamation, "Save Now?")
        Select Case Retval
            Case vbYes
                MsgBox "Would have saved " & CurrentKey & " _                       moving to " & Node.Index
                NeedsSaved = False
                Set tv.SelectedItem = tv.Nodes(Node.Index)
            Case vbNo
                MsgBox "Not being saved"
                NeedsSaved = False
                Set tv.SelectedItem = tv.Nodes(Node.Index)
        End Select
    End If

that you posted in NodeClick event. Place it in the TreeView Click event.

Cheers
0
 
LVL 1

Author Comment

by:sgroner
ID: 1487190
Sorry, but MelissaC had answered the question already.  Sorry, but I did not refresh my screen when I read her message.  Her solution helped, I must award the points to her.


0
 
LVL 2

Accepted Solution

by:
vspeter earned 100 total points
ID: 1487191
MelissaC solution was to place to code in the NODECLICK event. What I am saying is that, place in the CLICK event (TreeView1_Click) .
0
 
LVL 2

Expert Comment

by:MelissaC
ID: 1487192
I think you can use  a LONG best, just store the nodeID in it, that's all you need to find the node that was previously active. If you store it in a node, you have to copy the node's properties.
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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

18 Experts available now in Live!

Get 1:1 Help Now