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

VB.NET源码-156个实用实例哦…… <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
求助:关于取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 , 150, 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的代码全部贴出来。
__________________________________________________________________________
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值