vb.net 如何遍历treeview 并把子节点的text与string数组比较
1个回答
展开全部
你的treeview和数组是什么结构呢?这个源码你改改用吧
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim str(TreeView1.GetNodeCount(False) - 1, 0) As String '定义一个2维数组存放节点内容
Dim node As TreeNode
Dim childnode As TreeNode
Dim i, j As Integer
i = 0
For Each node In TreeView1.Nodes '循环根节点
j = 1
str(i, 0) = node.Text '每个根节点的内容存放在第一列
If UBound(str, 2) < node.GetNodeCount(False) Then
ReDim Preserve str(TreeView1.GetNodeCount(False) - 1, node.GetNodeCount(False)) '根据子节点的数目更改数组大小
End If
For Each childnode In node.Nodes '循环子节点
str(i, j) = childnode.Text '存放每个子节点的内容
j = j + 1
Next
i = i + 1
Next
node = Nothing
childnode = Nothing
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim str(TreeView1.GetNodeCount(False) - 1, 0) As String '定义一个2维数组存放节点内容
Dim node As TreeNode
Dim childnode As TreeNode
Dim i, j As Integer
i = 0
For Each node In TreeView1.Nodes '循环根节点
j = 1
str(i, 0) = node.Text '每个根节点的内容存放在第一列
If UBound(str, 2) < node.GetNodeCount(False) Then
ReDim Preserve str(TreeView1.GetNodeCount(False) - 1, node.GetNodeCount(False)) '根据子节点的数目更改数组大小
End If
For Each childnode In node.Nodes '循环子节点
str(i, j) = childnode.Text '存放每个子节点的内容
j = j + 1
Next
i = i + 1
Next
node = Nothing
childnode = Nothing
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询