Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 28th, 2005, 09:54 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default MSTree View - Sync problem


I am using the MS tree view ocx to allow users to navigate through a master detail situation. I have no problems loading the control and syncing the form recordset to the selected item in the tree view when an item is clicked. What I want to do is sync the tree view control to the selected record so when the on current event fires it finds the related item in the tree view control. The ocx does not have a method for this. and so I need an alternative. Any suggesstions are welcome!!

Jp
Reply With Quote
  #2 (permalink)  
Old January 30th, 2005, 08:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Jp,

This will select a node in the treeview that corresponds to the current record on the Main form (I'm assuming there is only one form involved, i.e. no subform), expand any parent nodes the selected node may have, and highlight the selected node. Be sure the "HideSelection" property of the ocx is set to 'No' ('Yes' is the default).

Private Sub Form_Current()

    On Error GoTo ErrorHandler

    ' Get a refernece to the TreeView control
    ' on the Main form.
    Set oTreeView = Me!TreeView1

    If Not oTreeView Is Nothing Then

        Dim strKey As String
        strKey = Me!ItemText

        Set oNode = oTreeView.Nodes(strKey)
        oTreeView.SelectedItem = oNode
        oNode.EnsureVisible

    End If

    Exit Sub

ErrorHandler:
    If Err.Number = 35601 Then 'Element not found
        MsgBox "There is no Node key corresponding to the current record."
        Exit Sub
    Else
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Sub

To make this work, you have to reference the nodes collection by node key, which mean the node key has to be set as you add each node to the nodes collection. I'm basing the Main form's recordset on a single table with some real simple data like:
Code:
"ItemID"    "ItemText"
1            "Parent1"
2            "Parent2"
3            "Parent3"
4            "Child1"
5            "Child2"
6            "Child3"
7            "Child4"
8            "Child5"
9            "Child6"
So as each node is added to the nodes collection, its key gets set to a corresponding data element, like:

Private Sub Form_Load()
    Dim oNode As Node
    Dim i As Integer

    'Add method arguments
    'object.Add(relative, relationship, key, text, image, selectedimage)

    For i = 1 To 3
        Set oNode = TreeView1.Nodes.Add(, , "Parent" & CStr(i), "Parent" & CStr(i))
    Next i

    Set oNode = TreeView1.Nodes.Add(1, 4, "Child1", "Child1")
    Set oNode = TreeView1.Nodes.Add(1, 4, "Child2", "Child2")
    Set oNode = TreeView1.Nodes.Add(2, 4, "Child3", "Child3")
    Set oNode = TreeView1.Nodes.Add(2, 4, "Child4", "Child4")
    Set oNode = TreeView1.Nodes.Add(3, 4, "Child5", "Child5")
    Set oNode = TreeView1.Nodes.Add(3, 4, "Child6", "Child6")

End Sub

I hard coded this stuff just to keep it simple, but you're probably using some sort of loop to populate your treeview from a recordset, in which case just to something like:

Set oNode = TreeView1.Nodes.Add()
With oNode
    .Key = "Key_" & rst("ItemText") 'or ItemID, which ever you prefer
    .Text = rst("ItemText")
End With

Once the key is set, you should be good to go.

HTH,

Bob

Reply With Quote
  #3 (permalink)  
Old January 31st, 2005, 04:34 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Bob!

I didn't think of setting a reference to the node! I was thinking of some sort of 'Find First'!!! (Doh!)

Pefect, the db is doing exactly what I wanted. Thanks alot!!!:D
Reply With Quote
  #4 (permalink)  
Old January 31st, 2005, 06:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

My pleasure JpJoe! Glad its working OK for you. :)

Bob

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sync FormView and DataList CB40 ASP.NET 2.0 Basics 1 January 26th, 2008 10:43 PM
Database Sync Rangatharan .NET Framework 2.0 1 August 20th, 2007 02:37 AM
asynch vs. sync hdwriter BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 April 11th, 2007 10:22 PM
MySQL Sync rajuru MySQL 2 November 9th, 2006 10:08 AM
A Better way to sync a remote and local database? kevorkian SQL Server 2000 1 April 5th, 2005 08:09 AM



All times are GMT -4. The time now is 09:58 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.