[VB.NET]求助:关于取treeview父结点的问题.(在线...)

前端之家收集整理的这篇文章主要介绍了[VB.NET]求助:关于取treeview父结点的问题.(在线...)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
求助:关于取treeview父结点的问题.(在线...) 我想取得某一结点(d)在treeview中的路径:a/b/d a id context parent ├b 1 a 0 │└d 2 b 1 └c 3 c 1 4 d 2 ***************************************************** * While (ParentNode.ID <> 0) * * ParentNode = ParentNode.Parent * * 取得父结点的ID和Text * * newPARENTID = ParentNode.ID * * newCONTEXT = ParentNode.Text * * ?合目? * * Directory = newCONTEXT + / + Directory * * 到?根?点退出循? * * End While * ***************************************************** 可是取到最后,ParentNode = ParentNode.Parent 会出错. 如果把条件改成(ParentNode.ID > 1),不会出错,可是取不到父结点的路径. 求助,我是新手~~~~ __________________________________________________________________________ if( ParentNode.Parent isnot nothing ) then ParentNode = ParentNode.Parent .... .... else .... endif __________________________________________________________________________ 改成> 0呢? __________________________________________________________________________ 改成> 0呢? __________________________________________________________________________ 先找到此项: Dim myNode As TreeNode For Each myNode In a MsgBox(nd.Text) MsgBox(nd.p) nd.Nodes.g() If myNode.Text = Trim(TextBox4.Text) Then TreeView1.SelectedNode = myNode myNode.Nodes.Add( 加了 ) myNode.Expand() Exit For End If traverse(myNode.Nodes) Next End Sub 然后取其mynode.parent.text即可 __________________________________________________________________________ Private Sub Form1_Load(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles MyBase.Load Me.ListView1.View = View.Details Me.ListView1.GridLines = True Me.ListView1.Columns.Add( Name,150,HorizontalAlignment.Left) Me.ListView1.Columns.Add( CreationTime,HorizontalAlignment.Left) Dim drive As String For Each drive In Environment.GetLogicalDrives Dim cNode As New TreeNode() cNode.Text = drive.ToString Me.TreeView1.Nodes.Add(cNode) Next End Sub Private Sub TreeView1_AfterSelect(ByVal sender As Object,_ ByVal e As System.Windows.Forms.TreeViewEventArgs) _ Handles TreeView1.AfterSelect Me.ListView1.Items.Clear() Try Dim dir As New DirectoryInfo(Me.TreeView1.SelectedNode.Text) Dim di As DirectoryInfo() = dir.GetDirectories() Dim i As Integer 取目录=========关键所在 For i = 0 To di.Length - 1 If Not di(i).Name.Equals( . ) And Not di(i).Name.Equals( .. ) Then Me.ListView1.Items.Add(di(i).Name) Me.ListView1.Items(i).SubItems.Add(di(i).CreationTime.ToString()) End If Next i Catch di As Exception MessageBox.Show(di.Message) End Try End Sub __________________________________________________________________________ to:neil_cn(Neil) 最後一次取到的ParentNode.Parent的id是 TreeView1 , 所以用isnot nothing 作为判断条件仍然会回到循环里。 to:magicbacon(Cannot help coding) 改成> 0也不好用。 to:cgtsea() 有点难,没看懂。我琢磨琢磨哈。 > _ __________________________________________________________________________ 利用 depth 以及 type is nothing __________________________________________________________________________ 楼主,我很关注这个问题,能不能把加载treeview的代码全部贴出来。 __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263455.html

猜你在找的VB相关文章