带查找功能的下拉目录树 录入窗口钮下目录内容後会改编表中的内容?
计下拉窗口
1、新建一个窗口,名为“窗口1”,窗口类型设置为“DropDownForm”。
2、分别插入一个TreeVew和Button控件。
3、窗口的AfterLoad事件代码设置为:
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree("行政区域","省市|县市")
4、窗口的DropDownOpened事件代码设置为:
e.Form.DropDownBox.Select()
5、TreeView控件的NodeMouseClick事件代码设置为:
If e.Node.Level = 1 Then '如果单击的是第二层节点
Dim tr As Row = Tables("客户").Current
Dim dr As DataRow = e.Node.DataRow '获取生成此节点的DataRow
tr("省市") = dr("省市")
tr("县市") = dr("县市")
tr("区号") = dr("区号")
tr("邮编") = dr("邮编")
e.Form.DropDownBox.Value = tr("县市")
e.Form.DropDownBox.CloseDropdown()
End If
6、Button控件的Click事件代码设置为:
Dim txt As String = e.Form.DropDownBox.Text
If txt = "" Then '如果下拉框没有输入内容,则无需查询
Return
End If
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim Start As Integer
Dim idx As Integer = - 1
If trv.SelectedNode IsNot Nothing Then '获取当前节点位置.
Dim FullName As String = trv.SelectedNode.FullName
For i As Integer = 0 To trv.AllNodes.count - 1
If trv.AllNodes(i).FullName = FullName Then
Start = i
Exit For
End If
Next
End If
For i As Integer = Start + 1 To trv.AllNodes.count - 1 '从当前节点的下一个节点开始查找
Dim nd As WinForm.TreeNode = trv.AllNodes(i)
If nd.Text.IndexOf(txt) >= 0 Then
trv.SelectedNode = nd
nd.EnsureVisible
idx = i '将找到的位置复制给变量idx
Exit For
End If
Next
If idx = -1 Then 'idx的值如果等于初始值-1,表示没有找到下一个符合条件的节点,那么从第一个节点开始重新查找.
For i As Integer = 0 To Start - 1
Dim nd As WinForm.TreeNode = trv.AllNodes(i)
If nd.Text.IndexOf(txt) >= 0 Then
trv.SelectedNode = nd
nd.EnsureVisible
Exit For
End If
Next
End If
trv.Select()
[此贴子已经被作者于2019/2/22 15:30:13编辑过]