November 10th, 1999, 04:36 AM
' 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)
' 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)