G
Guest
I have a form with treeview control loaded from xml document,text box, two
buttons named "Find" and "FindNext" and my treeview which looks like below.
Details
|__ policy status
|__ created by
|__ cover type
Risk address
|__Line1
|__Line2
|__Line3
|__Line4
Proposers
|__ForeName
|__Initials
|__Surname
|__Company
|__DOB
Drivers
|__ForeName
|__Initials
|__Surname
|__Company
when user enters some text in text box like "Surname" and click "find"
button i need to select(highlight) the "surname" node in "proposers" node in
treeview which i have done by using the following code.
Dim blnSelectNode As Boolean = False
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFind.Click
Try
Dim textval As String = ""
textval = Trim(txtFind.Text) 'textbox value
If Len(textval) = 0 Then
MsgBox("Please enter some text to find")
txtFind.Focus()
Else
' write code to find nodes or childs
blnSelectNode = False
LoopParents(textval, Me.TreeView1.Nodes)
If Not blnSelectNode Then MsgBox("Node not found",
MsgBoxStyle.Information, "Document Manager")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub LoopParents(ByVal sValue As String, ByVal oNodes As
TreeNodeCollection)
Dim tnode
For Each tnode In oNodes
If InStr(LCase(tnode.Text), sValue) > 0 Then
Me.TreeView1.SelectedNode = tnode
Me.TreeView1.Select()
blnSelectNode = True
Exit Sub
End If
If Not blnSelectNode Then LoopChilds(tnode, sValue)
Next
End Sub
Private Sub LoopChilds(ByVal PNode As TreeNode, ByVal sValue As String)
Dim TNode As TreeNode
For Each TNode In PNode.Nodes
If InStr(LCase(TNode.Text), sValue) > 0 Then
Me.TreeView1.SelectedNode = TNode
Me.TreeView1.Select()
blnSelectNode = True
Exit Sub
End If
Next
End Sub
Now i need to select the next matching node(if found) i.e "surname" in
"Drivers" node when user clicks the "findnext" button. I am not sure how to
do this one. All i need to do is select(highlight) the next matching node in
treeview control.
Any help would be appreciated
Cheers
Praveen
buttons named "Find" and "FindNext" and my treeview which looks like below.
Details
|__ policy status
|__ created by
|__ cover type
Risk address
|__Line1
|__Line2
|__Line3
|__Line4
Proposers
|__ForeName
|__Initials
|__Surname
|__Company
|__DOB
Drivers
|__ForeName
|__Initials
|__Surname
|__Company
when user enters some text in text box like "Surname" and click "find"
button i need to select(highlight) the "surname" node in "proposers" node in
treeview which i have done by using the following code.
Dim blnSelectNode As Boolean = False
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFind.Click
Try
Dim textval As String = ""
textval = Trim(txtFind.Text) 'textbox value
If Len(textval) = 0 Then
MsgBox("Please enter some text to find")
txtFind.Focus()
Else
' write code to find nodes or childs
blnSelectNode = False
LoopParents(textval, Me.TreeView1.Nodes)
If Not blnSelectNode Then MsgBox("Node not found",
MsgBoxStyle.Information, "Document Manager")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub LoopParents(ByVal sValue As String, ByVal oNodes As
TreeNodeCollection)
Dim tnode
For Each tnode In oNodes
If InStr(LCase(tnode.Text), sValue) > 0 Then
Me.TreeView1.SelectedNode = tnode
Me.TreeView1.Select()
blnSelectNode = True
Exit Sub
End If
If Not blnSelectNode Then LoopChilds(tnode, sValue)
Next
End Sub
Private Sub LoopChilds(ByVal PNode As TreeNode, ByVal sValue As String)
Dim TNode As TreeNode
For Each TNode In PNode.Nodes
If InStr(LCase(TNode.Text), sValue) > 0 Then
Me.TreeView1.SelectedNode = TNode
Me.TreeView1.Select()
blnSelectNode = True
Exit Sub
End If
Next
End Sub
Now i need to select the next matching node(if found) i.e "surname" in
"Drivers" node when user clicks the "findnext" button. I am not sure how to
do this one. All i need to do is select(highlight) the next matching node in
treeview control.
Any help would be appreciated
Cheers
Praveen