如果用户从上下文菜单中选择“重命名"选项,我想重命名Treeview的子节点 [英] I would like to rename the child node of treeview if the user selects Rename option from context menu

查看:73
本文介绍了如果用户从上下文菜单中选择“重命名"选项,我想重命名Treeview的子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我的树状视图如下:
http://lh6.ggpht. com/_3_c9olh5X7s/THixEj1Lj9I/AAAAAAAADls/8cJnq33Ksso/s800/8-28-2010%2012-16-14%20 PM.png

如果我右键单击名为.txt的文件,那么如果用户选择我要执行以下操作,我将有一个重命名之类的选项:

1.显示对话框提示输入名称.
2.在TreeView控件中更改节点的文本.
3.在路径

Hi all,
I am having a treeview as follows:
http://lh6.ggpht.com/_3_c9olh5X7s/THixEj1Lj9I/AAAAAAAADls/8cJnq33Ksso/s800/8-28-2010%2012-16-14%20PM.png

If i right click on the files which are named as .txt i will have an option like rename if user selects that i would like to do the following things:

1. Displaying dialog to prompt for the name.
2. Changing the text of the node in the TreeView control.
3. Replacing the old file with the current file name in the path

推荐答案

中用当前文件名替换旧文件,并将树视图的属性设置为

treeView1.LabelEdit = true;

这样您就可以轻松地编辑节点文本.那么您可以处理事件"BeforeLabelEdit",以验证文件的新名称并更改文件名(我只是将文件复制到新名称,然后删除现有名称,这很懒惰:)).要验证新文件名,您可以使用

System.IO.Path.GetInvalidFileNameChars()

获取非法字符列表.

希望对您有帮助,祝您好运.
well set the treeview''s property as

treeView1.LabelEdit = true;

that will allow you to edit the node text easily. then you can handle the event "BeforeLabelEdit" to validate the new name of the file and change the file name (I would just copy the file to the new name and delete the existing one, am just lazy :) ). To validate the new file name you can use

System.IO.Path.GetInvalidFileNameChars()

to obtain list of illegal characters.

Hope this helps, good luck.


这篇关于如果用户从上下文菜单中选择“重命名"选项,我想重命名Treeview的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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