Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
有这样一个物料表
父编码 子编码
a a1
b b1
c c1
a1 aa1
b1 bb1
c1 cc1
aa1 d1
请教如何能做成下面结构,在窗口的目录树中展现(treeview)
-a
- a1
-aa1
-d1
-b
-b1
-bb1
-c
-c1
-cc1
开动脑筋,不难的。
要是这样的规则:
父码 子码
a a1
b b1
c c1
a1 aa1
b1 bb1
c1 cc1
aa1 aaa1 【 你原来时 d1 】
可以这样:
Dim s,s1,s2,s3 As String
s = DataTables("表A").GetComboListString("父码")
s1 = s & "|" & DataTables("表A").GetComboListString("子码")
s2 = ""
For i0 As Integer = 0 To s1.split("|").length-1
If s2.contains(s1.split("|")(i0)) = False
s2 = s2 & s1.split("|")(i0) & "|"
End If
Next
Dim tr As WinForm.TreeView = Forms("目录树").Controls("TreeView1")
Dim nd0,nd1,nd2,nd3,nd4 As WinForm.TreeNode
tr.Nodes.Clear '清空原来的节点::::::::::
For i As Integer = 0 To s2.split("|").length-1
s3 = s2.split("|")(i).length
Select Case s3
Case 1
nd0 = tr.Nodes.Add(Rand.NextString(10),s2.split("|")(i))
output.show(nd0.text)
Case 2
If s2.split("|")(i).contains(nd0.text)
nd1 = nd0.Nodes.Add(Rand.NextString(10),s2.split("|")(i))
End If
Case 3
If s2.split("|")(i).contains(nd1.text)
nd2 = nd1.Nodes.Add(Rand.NextString(10),s2.split("|")(i))
End If
Case 4
If s2.split("|")(i).contains(nd2.text)
nd3 = nd2.Nodes.Add(Rand.NextString(10),s2.split("|")(i))
End If
End Select
Next
结果这样对吗:
呵呵,我也来一个,我这个对于名称没有任何要求的:
Dim lst1 As List(of String) = DataTables("表A").GetUniqueValues("","第一列")
Dim lst2 As List(of String) = DataTables("表A").GetUniqueValues("","第二列")
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim tnd As WinForm.TreeNode
Dim dr As DataRow
trv.Nodes.Clear()
For Each Val As String In Lst1
If lst2.Contains(val) = False Then
tnd = trv.Nodes.Add(val,val)
Do
dr = DataTables("表A").Find("第一列 = '" & tnd.Name & "'")
If dr Is Nothing Then
Exit Do
Else
tnd = tnd.Nodes.Add(dr("第二列"),dr("第二列"))
End If
Loop
End If
Next
下载信息 [文件大小: 下载次数: ] | |
![]() |
收藏
收藏
呵呵,不用收藏的,关键是把他看明白。
另外,4楼代码在生成目录树前,要对 s2 进行一下排序,否则会乱了。。。。 呵呵
呵呵,我也来一个,我这个对于名称没有任何要求的:
Dim lst1 As List(of String) = DataTables("表A").GetUniqueValues("","第一列")
Dim lst2 As List(of String) = DataTables("表A").GetUniqueValues("","第二列")
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim tnd As WinForm.TreeNode
Dim dr As DataRow
trv.Nodes.Clear()
For Each Val As String In Lst1
If lst2.Contains(val) = False Then
tnd = trv.Nodes.Add(val,val)
Do
dr = DataTables("表A").Find("第一列 = '" & tnd.Name & "'")
If dr Is Nothing Then
Exit Do
Else
tnd = tnd.Nodes.Add(dr("第二列"),dr("第二列"))
End If
Loop
End If
Next
下载信息 [文件大小:296.0 KB 下载次数:14] | |
![]() |
aa1 d2
就不行了的