AfterCheckNode事件完整代码发上来看看
直接用Dim rts() As String = e.node.FullPath.Split("\")
就可实现取当前目录树路径了。
此主题相关图片如下:微信图片_20240416133922.png
此主题相关图片如下:微信图片_20240416133958.png
目录树结构如上面两图,我省去多选的代码,勾选的代码我测试过没问题了,问题在生成的筛选数据,我这样写时只显示当前勾选的数据,不同一路径的没显示了,如何把不同路径的数据同时显示:
Dim trv As WinForm.TreeView = e.Sender
Dim flt, flt0, flt1, flt2, flt3, flt4 , flt5 As String
Dim nd As WinForm.TreeNode
Dim nms As String() = {"明细分类", "住址_巷", "住址_号", "住址_房", "车牌号码", "姓名", "手机号码"} '指定生成目录树的各列
Dim qts As String() = {"'", "'", "'", "'", "'", "'", "'"} '指定将各列的值括起来的符号,这里都是字符型,所以都是单引号
Dim nms1 As String() = {"明细分类", "年", "月", "车牌号码", "姓名", "手机号码"} '指定生成目录树的各列
Dim qts1 As String() = {"'", "", "", "'", "'", "'"} '指定将各列的值括起来的符号,这里都是字符型,所以都是单引号
Dim nms2 As String() = {"住址_巷", "住址_号", "住址_房", "单位名称", "姓名", "手机号码"} '指定生成目录树的各列
Dim qts2 As String() = {"'", "'", "'", "'", "'", "'"} '指定将各列的值括起来的符号,这里都是字符型,所以都是单引号
Dim nms3 As String() = {"单位名称", "姓名", "手机号码"} '指定生成目录树的各列
Dim qts3 As String() = {"'", "'", "'"} '指定将各列的值括起来的符号,这里都是字符型,所以都是单引号
Dim nms4 As String() = {"明细分类", "车牌号码", "姓名", "手机号码"} '指定生成目录树的各列
Dim qts4 As String() = {"'", "'", "'", "'"} '指定将各列的值括起来的符号,这里都是字符型,所以都是单引号
If e.node.Checked Then
Dim rts() As String = e.node.FullPath.Split("\")
Dim val As String = ""
Dim val1 As String = ""
If e.Node.Level = 0 Then
flt = "分类 = '" & rts(0) & "'"
ElseIf e.Node.Level >= 1 Then
If rts(0) = DataTables("分类").DataRows(0)("分类") And (rts(1) = DataTables("用户明细分类").DataRows(0)("用户明细分类") Or rts(1) = DataTables("用户明细分类").DataRows(1)("用户明细分类")) Then
For i As Integer = 1 To rts.length - 1
If val1 > "" Then
val1 = val1 & " And " & nms(i - 1) & " = " & qts(i - 1) & rts(i) & qts(i - 1)
End If
val1 = nms(i - 1) & " = " & qts(i - 1) & rts(i) & qts(i - 1)
Next
If flt1 > "" Then
flt1 = flt1 & " Or (([分类]= '" & DataTables("分类").DataRows(0)("分类") & "Or [分类] = '" & _
DataTables("分类").DataRows(1)("分类") & "') And " & val1 & ")"
Else
flt1 = "([分类]= '" & DataTables("分类").DataRows(0)("分类") & "' Or [分类] = '" & DataTables("分类").DataRows(1)("分类") & _
"') And " & val1
End If
End If
If rts(0) = DataTables("分类").DataRows(0)("分类") And rts(1) = DataTables("用户明细分类").DataRows(2)("用户明细分类") Then
For i As Integer = 1 To rts.length - 1
If val > "" Then
val = val & " And " & nms4(i - 1) & " = " & qts4(i - 1) & rts(i) & qts4(i - 1)
End If
val = nms4(i - 1) & " = " & qts4(i - 1) & rts(i) & qts4(i - 1)
Next
If flt2 > "" Then
flt2 = flt2 & " Or ([分类] = '" & DataTables("分类").DataRows(0)("分类") & "' And " & val & ")"
Else
flt2 = "分类 = '" & DataTables("分类").DataRows(0)("分类") & "' And " & val
End If
End If
[此贴子已经被作者于2024/4/16 13:57:19编辑过]
If nd.FullPath Like DataTables("分类").DataRows(1)("分类") & "*" Then
Dim d1, d2 As Date
Select Case e.Node.Level
Case 1
If val > "" Then
val = val & " And (" & nms1(0) & " = " & qts1(0) & rts(1) & qts1(0) & ")"
Else
val = nms1(0) & " = " & qts1(0) & rts(1) & qts1(0)
End If
Case 2
d1 = New Date(CInt(rts(2)), 1, 1)
d2 = New Date(CInt(rts(2)), 12, 31)
val = nms1(0) & " = " & qts1(0) & rts(1) & qts1(0) & " And 日期 >= #" & d1 & "# And 日期 <=#" & d2 & "#"
MessageBox.Show(val)
Case 3
d1 = New Date(CInt(rts(2)), CInt(rts(3)), 1)
d2 = New Date(CInt(rts(2)), CInt(rts(3)), Date.DaysInMonth(CInt(rts(2)), CInt(rts(3))))
val = nms1(0) & " = " & qts1(0) & rts(1) & qts1(0) & " And 日期 >= #" & d1 & "# And 日期 <=#" & d2 & "#"
Case 4
d1 = New Date(CInt(rts(2)), CInt(rts(3)), 1)
d2 = New Date(CInt(rts(2)), CInt(rts(3)), Date.DaysInMonth(CInt(rts(2)), CInt(rts(3))))
val = nms1(0) & " = " & qts1(0) & rts(1) & qts1(0) & " And 日期 >= #" & d1 & "# And 日期 <=#" & d2 & "# And 车牌号码 = '" & rts(4) & "'"
Case 5
d1 = New Date(CInt(rts(2)), CInt(rts(3)), 1)
d2 = New Date(CInt(rts(2)), CInt(rts(3)), Date.DaysInMonth(CInt(rts(2)), CInt(rts(3))))
val = nms1(0) & " = " & qts1(0) & rts(1) & qts1(0) & " And 日期 >= #" & d1 & "# And 日期 <=#" & d2 & "# And 车牌号码 = '" & rts(4) & "' And 手机号码 = '" & rts(5) & "'"
End Select
flt3 = "分类= '" & DataTables("分类").DataRows(1)("分类") & "' And " & val
If nd.FullPath Like DataTables("分类").DataRows(2)("分类") & "*" Then
For i As Integer = 1 To rts.length - 1
If val > "" Then
val = val & " And "
End If
val = val & nms2(i - 1) & " = " & qts2(i - 1) & rts(i) & qts2(i - 1)
Next
If flt4 > "" Then
If flt4 > "" Then
flt4 = flt4 & " or (分类 = '" & DataTables("分类").DataRows(2)("分类") & "' And " & val & ")"
Else
flt4 = "分类 = '" & DataTables("分类").DataRows(2)("分类") & "' And " & val
End If
End If
End If
If nd.FullPath Like DataTables("分类").DataRows(3)("分类") & "*" Then
For i As Integer = 1 To rts.length - 1
If val > "" Then
val = val & " And "
End If
val = val & nms3(i - 1) & " = " & qts3(i - 1) & rts(i) & qts3(i - 1)
Next
If val > "" Then
If flt5 > "" Then
flt5 = flt5 & " or (分类 = '" & DataTables("分类").DataRows(3)("分类") & "' And " & val & ")"
Else
flt5 = "分类 = '" & DataTables("分类").DataRows(3)("分类") & "' And " & val
End If
End If
End If
End If
End If
If flt0 > "" Then
If flt > "" Then
flt = flt & " Or "
End If
flt = flt & "(" & flt0 & ")"
End If
If flt1 > "" Then
If flt > "" Then
flt = flt & " Or "
End If
flt = flt & "(" & flt1 & ")"
End If
If flt2 > "" Then
If flt > "" Then
flt = flt & " Or "
End If
flt = flt & "(" & flt2 & ")"
End If
If flt3 > "" Then
If flt > "" Then
flt = flt & " Or "
End If
flt = flt & "(" & flt3 & ")"
End If
If flt4 > "" Then
If flt > "" Then
flt = flt & " Or "
End If
flt = flt & "(" & flt4 & ")"
End If
If flt5 > "" Then
If flt > "" Then
flt = flt & " Or "
End If
flt = flt & "(" & flt5 & ")"
End If
End If
With DataTables("车辆基本信息")
.LoadFilter = flt '设置加载条件
.LoadPage = 0 '加载第一页
.LoadTop = 30 '每页5行
.LoadOrder = "_Identify"
.LoadReverse = True
.Load()
e.Form.Controls("TextBox2").Value = 1 & "/" & .TotalPages
End With
此主题相关图片如下:微信图片_20240416212943.png
你安我图上这样勾选,报错。
建议不要一次性筛选过多数据,筛选条件的长度是有限制的哦
,全选后去除一个勾选,也就是除没勾选的这个外,其他都显示,这样操作常有啊!如此说来这方法失败!