private void SelectByID(TreeView tv,string ID)
{
foreach(TreeNode tn in tv.Nodes)
{
if(rec(tv,tn,ID))
{
break
}
}
}
private bool rec(TreeView tv,TreeNode tn,string ID)
{
string ss=tn.Text
if(tn.ID==ID)
{
tv.SelectedNodeIndex=tn.GetNodeIndex()
return true
}
else
{
bool t=false
foreach(TreeNode ctn in tn.Nodes)
{
if(rec(tv,ctn,ID))
{
t=true
break
}
}
return t
}
}
或者(遍历选中节点)
private void GetTreeSelected(TreeNodeCollection trees)
{
foreach(TreeNode tn in trees)
{
if(tn.Checked)
{
//执行相应的 *** 作
}
if(tn.Nodes.count!=0)
GetTreeSelected(tn.Nodes)
}
}
Private Sub Command1_Click()Dim i As Integer
Dim nd As Node
List1.Clear
Set nd = TreeView1.SelectedItem.Child
For i = 1 To TreeView1.SelectedItem.Children
List1.AddItem nd.Text
Set nd = nd.Next
Next
End Sub
Private Sub Form_Load()
Dim i As Integer, j As Integer
TreeView1.LineStyle = tvwRootLines
TreeView1.LabelEdit = tvwManual
TreeView1.Nodes.Add , , "R", "R"
For i = 1 To 5
TreeView1.Nodes.Add "R", tvwChild, "A" &i, "A" &i
For j = 1 To 5
TreeView1.Nodes.Add "A" &i, tvwChild, "A" &i &"B" &j, "A" &i &"B" &j
Next
Next
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)