Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Posts
    173

    Unanswered: Need Help with TreeView

    I found a sample db online (see attached). It works well, however; when you click a Category, I would like to show the product code and the description instead of just the description.

    Ex:

    Water
    2P-001 - 2" Pipe
    4P001 - 4" Pipe

    4P-001 is the Product Code and 4" Pipe is the Description

    Instead of what the sample is showing

    Water
    2" Pipe
    4" Pipe



    I looked at the code behind the form, but could not figure it out right off.

    Can anyone tell me how to control the fields loaded in the treeview control.

    Thanks - AB
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    I'm going to assume that you want this for display purposes only. If this is indeed the case then the return sample attachement will do the task.

    Here is how it was accomplished – first put your Form into Design View:

    1) Rename the Product TextBox to ViewProduct.
    2) Make sure this new ViewProduct TextBox contains nothing in the ControlSource property (make it unbound).
    3) Create another new TextBox near the bottom of the form (where the other non-visible controls are) and name it Product.
    4) Set the Visible property for this new Product TextBox to False (so it can’t be seen).
    5) Set (bind) this new Product TextBox ControlSource property to Product.
    6) Open the VB code editor and locate the Function named ‘ChangeView’. Change the line that states Me.Product.Visible = I to Me.ViewProduct.Visible = i
    7) Get out of the VBE and back to Form. Enter this code into the Forms’ OnCurrent event so that it looks something like this:
    Code:
    Private Sub Form_Current()
    	If IsNull(Me.ProductCode) Then
    	 MsgBox "There appears to be no Product Code for this item." & vbNewLine & _
    	 "A Product Code should be supplied.", vbExclamation, "No Product Code"
    	End If
    	Me.ViewProduct = Me.ProductCode & " - " & Me.Product
    End Sub

    8) Save and restart your DB.

    That’s it….



  3. #3
    Join Date
    Aug 2004
    Posts
    173

    Thanks - But Not What I Need to Do

    Thanks for the reply. What I am trying to do is get the node in the TreeView to show the Product Code and Product Name when a category is clicked. Everything else works fine.

    Thanks - Anthony

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Ohhh..Ok then....forget about all the jiberish above then....Just as well since I fell asleep and forgot add the DB attachment. It is here now and it does what you want:

    I did it by going into the VBE and changing this line within the Buildbranch subroutine:

    CHANGE:
    Code:
    Set nodCurrent = oTree.Nodes.Add(strKey, tvwChild, strKey2, rstSub!Product)
    TO STATE:
    Code:
    Set nodCurrent = oTree.Nodes.Add(strKey, tvwChild, strKey2, rstSub!ProductCode & " - " & rstSub!Product)
    Here is the DB back to you:

    Attached Files Attached Files

  5. #5
    Join Date
    Aug 2004
    Posts
    173

    Thank You - Works Perfectly

    Thanks so much for the fast and effective solution.
    I am just beginning to use the TreeView and learning how to modify it.

    AB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •