?
Solved

Treeview Control

Posted on 1998-09-28
10
Medium Priority
?
255 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:Steve Groner
  • 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:Steve Groner
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

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

Author Comment

by:Steve Groner
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:Steve Groner
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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 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…
Suggested Courses

829 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