CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    What's wrong with this code


    ' You need a combobox and a treeview.
    ' A want to be able to type in a path in the combobox and make the treeview jump to it when i press enter.
    ' The separator = ", "

    private Sub Form_Load()

    Dim nodX as Node ' Declare Node variable.

    set nodX = TreeView1.Nodes.Add(, , "r", "Root")
    set nodX = TreeView1.Nodes.Add(, , "s", "Soot")
    set nodX = TreeView1.Nodes.Add("r", tvwChild, "child1", "Child 1")
    set nodX = TreeView1.Nodes.Add("r", tvwChild, "child2", "Child 2")
    set nodX = TreeView1.Nodes.Add("child1", tvwChild, "child3", "Child 3")
    set nodX = TreeView1.Nodes.Add("s", tvwChild, "child4", "Child 4")
    End Sub

    public Function SplitPathComponents(byval pPath as string, byval pSeparator as string) as Variant
    Dim arrTemp() as string
    Dim strTemp as string
    Dim i as Integer

    Do Until pPath = ""
    If InStr(pPath, pSeparator) > 0 then
    strTemp = Left(pPath, InStr(pPath, pSeparator) - 1)
    pPath = mid(pPath, InStr(pPath, pSeparator) + 1)
    else
    If pPath <> "" then
    strTemp = pPath
    pPath = ""
    End If
    End If
    ReDim Preserve arrTemp(i)
    arrTemp(i) = Trim(strTemp)
    i = i + 1
    Loop

    SplitPathComponents = arrTemp
    End Function

    private Sub Combo1_KeyPress(KeyAscii as Integer)
    Dim arrComp as Variant
    Dim i as Integer
    Dim iNode as Integer
    Dim iIndex as Integer
    Dim bFirstChild as Boolean

    If KeyAscii = 13 then
    'This will split the path and put it in array
    arrComp = SplitPathComponents(Combo1.Text, ",") 'You can specify any delimeter (separator)
    With TreeView1
    for i = 0 to UBound(arrComp)
    If i = 0 then
    for iNode = 1 to .Nodes.Count
    If UCase(.Nodes(iNode).Text) = UCase(arrComp(i)) then
    .Nodes(iNode).EnsureVisible
    .SetFocus
    .Nodes(iNode).Selected = true
    Exit for
    End If
    next
    else
    bFirstChild = true
    for iNode = 1 to .Nodes(i).Children
    If bFirstChild then
    If UCase(.Nodes(i).Child.Text) = UCase(arrComp(i)) then
    .Nodes(i).Child.EnsureVisible
    .SetFocus
    .Nodes(i).Child.Selected = true
    Exit for
    bFirstChild = false
    End If
    else
    If UCase(.Nodes(i).Child.next.Text) = UCase(arrComp(i)) then
    .Nodes(i).Child.EnsureVisible
    .SetFocus
    .Nodes(i).Child.Selected = true
    Exit for
    End If
    End If
    next
    End If
    next
    End With
    End If
    End Sub




    Typing in the following strings don't work in this example:
    root, child 1, child 3 (Child 3 is not selected)
    root, child 2 (Child 2 is not selected)
    soot, child 4 (Child 4 is not selected)



  2. #2
    Join Date
    Aug 1999
    Posts
    10

    Re: What's wrong with this code

    I posted the reply on the VB-World.net message board. Let me know how it's working out.


    Serge


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured