Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / ActiveX Controls / January 2005

Tip: Looking for answers? Try searching our database.

selecting treeview nodes programmatically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick McGuire - 03 Dec 2003 17:09 GMT
I agree with "Steve"
<anonymous@discussions.microsoft.com>  Dec 3 2003 8:28AM,
the literature regarding control treeview is pretty
abysmal.

I want to do several things:

1)  Find a node's index given its text
2)  Select a node programmatically based on its index
3)  Expand a node's immediate children if the node has
been selected programmatically

Can I do this with MSComctlLib.TreeCtrl.2?

Thanks,

Pat
Alex Dybenko - 04 Dec 2003 16:56 GMT
yes, i think all three can be done with treeview

Signature

Alex Dybenko (MVP)
http://Alex.Dybenko.com

> I agree with "Steve"
> <anonymous@discussions.microsoft.com>  Dec 3 2003 8:28AM,
[quoted text clipped - 13 lines]
>
> Pat
Patrick Lajoie - 13 Jan 2005 18:01 GMT
For those of you like me who found this tread because you had the same questions but did not find an answer, here's how I made it.  I get the name of the WBS ID I want to position to and when I build the tree node, I remember the index position of the WBS I wish to position automatically to.  (My WBS ID comes from another form which calls the tree node form.  I use the form containing my treenode to position to the WBS ID in the first form.
in my FindWBS form I have the following components:
Command Button: btnSel
   On Click:     [Event Procedure]
Text Box: bxtitle
Command Button: Cancelbtn
   On Click:     [Event Procedure]
ActiveX Control: wbslist
    Class:     MSComctlLib.TreeCtrl.2
    ControlType:     119
    Enabled:     True
    Name:     wbslist
    OLE Class:     TreeCtrl

Here's the code of the form "mdlfrm findwbs":

Option Compare Database
Option Explicit

Public wbssel As String

Private Sub btnSel_Click()
'returns the WBS ID selected to the form that called this modal form.
Fwbs = Me.bxtitle
DoCmd.Close
End Sub

Private Sub Cancelbtn_Click()
DoCmd.Close
End Sub

Private Sub Form_Load()
DoCmd.MoveSize 2 * 1440, 1.5 * 1440, 5.4 * 1440, 5.25 * 1440
On Error GoTo ErrorHandler
Dim i As Integer
Dim db As Database
Dim qr As QueryDef
Dim tb As Recordset
Dim trvDisplay As Control, imgList As Control
Dim nodObject As Node
Dim maxlev As Integer
Dim pwid() As String
Dim nodkey As String

'*** 20041103-PL-01-MOD01 begin********************************************
'Initialise l 'index du node à trouver et capture le WBS ID sur lequel il faut mettre le focus

Dim wbsIndex As Integer
Dim WBSid As String
wbsIndex = 1
WBSid = Forms!frmwbs!txtID
'*** 20041103-PL-01-MOD01 end********************************************

Set db = CurrentDb
Set qr = db.QueryDefs("qryfindwbslist")
qr.Parameters("pid") = Forms!frmwbs.combo61
maxlev = leveling(qr)
Set tb = qr.OpenRecordset
'treeview relative,relationship,key,text,image,selectedimage

Set trvDisplay = Me!wbslist
'Set imgList = Me!imlist
'trvDisplay.ImageList = imgList.Object
ReDim pwid(maxlev)

tb.MoveFirst
If IsNull(tb!Level) Then ranking
With trvDisplay.Nodes
   Do
       nodkey = "Node" & tb!ID
       If tb!Level = 1 Then
           'Set nodObject = .Add(, , nodkey, tb!ID & " - " & tb!Title, 1)
                   Set nodObject = .Add(, , nodkey, tb!ID & " - " & tb!Title)
   
           nodObject.Expanded = True
       Else
       
           Set nodObject = .Add(pwid(tb!Level - 1), tvwChild, nodkey, tb!ID & " - " & tb!Title)
       
       End If
       pwid(tb!Level) = nodkey
       
       '*** 20041103-PL-01-MOD01 begin********************************************
       'find the index of the wbs id passed in parameter
       If WBSid = tb!ID And Not IsNull(WBSid) Then wbsIndex = nodObject.Index
       '*** 20041103-PL-01-MOD01 end********************************************
       
       tb.MoveNext
   Loop Until tb.EOF

End With
tb.Close

'*** 20041103-PL-01-MOD01 begin********************************************
                       
           If Not IsNull(wbsIndex) Then
               ' select the node selected by the wbs ID
               trvDisplay.Nodes(wbsIndex).Selected = True
               trvDisplay.Nodes(wbsIndex).EnsureVisible
               trvDisplay.SetFocus
           Else
               ' pop to the top
               trvDisplay.Nodes(1).Root.Selected = True
               trvDisplay.Nodes(1).Root.EnsureVisible
               trvDisplay.SetFocus
           End If
           'refresh the display
           wbslist_click
           

   
   Exit Sub
ErrorHandler:
If Err.Number <> 0 Then
Dim Errormsg As String
If Err.Number = 35602 Then
   Errormsg = "The following WBS Item has been found as duplicate: " & tb!ID & " - " & tb!Title _
           & Chr(13) & "It will not be available in the search tree."
   MsgBox (Errormsg), vbExclamation
   Resume Next
Else
   Errormsg = "Error # " & str(Err.Number) & " was generated by " _
           & Err.Source & Chr(13) & Err.Description
   MsgBox Errormsg, , "Error", Err.HelpFile, Err.HelpContext
End If
Exit Sub
End If
           
'*** 20041103-PL-01-MOD01********************************************
End Sub

Private Sub wbslist_click()
'Assign the selected WBS ID from the node selected with the mouse to display in a textbox
Me.bxtitle = Mid(Me.wbslist.SelectedItem.Key, 5)
End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.