Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Apr 2001
    Location
    Washington, Washington, USA
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Programmatically Select Item in Treeview Control (Word 2000/VBA 6)

    I have a treeview control on my form that opens with the list of folders (something like Windows Explorer, although we mostly aren't using it for file management). When a certain button is pressed, another dialog box opens which allows the user to create a new folder. Once this is done, the original dialog box opens again. I want the new folder to be selected, but I can't figure out how to do it when I know the full path but not the index. My code so far is something like this:

    Load frmFileCodeSelect
    frmFileCodeSelect.TV.SetFocus
    frmFileCodeSelect.TV.Nodes.Item(strNewFolder).Sele cted = True
    frmFileCodeSelect.Show

    (where strNewFolder is the FullPath of the new item)

    I get an "Element not found" error on the SelectedItem = True line.

    Many thanks!

    --Karyl

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Programmatically Select Item in Treeview Control (Word 2000/VBA 6)

    Try something like this:

    Dim nod As Node

    frmFileCodeSelect.TV.SetFocus

    For Each nod In frmFileCodeSelect.TV.Nodes
    If nod.FullPath = strNewFolder Then
    nod.Selected = True
    Exit For
    End If
    Next nod

    Set nod = Nothing

Posting Permissions

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