更改树视图的节点值 [英] Changing the node value of treeview

查看:34
本文介绍了更改树视图的节点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我已经编写了一个代码来将文件从原始路径移动到新路径,这工作正常.

Hi all i have written a code to move a file from the original path to the new path this was working fine.

最初我的树视图将有一个根节点,我在运行时添加子节点.我的树如下

Initially my treeview will have a root node and i am adding child nodes at the run time. My tree is as follows

        Root
          |->C:\some.txt(Assume that it is in c drive)

现在,如果我右键单击它,我将有一个上下文菜单,其中包含移动和其他选项.如果我选择移动,我会要求用户更改路径.如果用户选择路径,我会将文件移动到选定的目的地.现在我需要的是我想用新路径替换树视图的当前子项.

Now if i right click on that i will have a context menu with options Move and some other. If i select move i will ask the user for changing the path. If the user selects a path i am moving the file to the selected destination. Now what i need is i would like to replace the current child of the treeview with the new path.

就像最初的 mt 文件在 c: 如果我把它移到 D:

Like initially mt file was in c: if i moved it to D:

我应该有我的树

          Root
            |->D:\some.txt

推荐答案

向表单中添加成员变量:

Add a member variable to your form as:

private Point location; 

将处理程序添加到 TreeView 上的 MouseDown 事件:

Add a handler to the MouseDown event on the TreeView as:

private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
    location = e.Location;
}

在移动菜单单击事件的事件处理程序中执行如下操作:

In the event handler for the move menu click event do something like:

TreeViewHitTestInfo info =  treeView1.HitTest(location);
info.Node.Text = "new path";

这篇关于更改树视图的节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆