2011-12-30 48 views
1

这里是CodePlex上的所有我所做的是创建一个新的文本框,并试图让选择进入这个文本框当前节点的路径中的应用程序,但我得到额外的事情,我不需要在所有的,树视图FULLPATH剥离

链接到应用程序,

Codeplex app

代码行我现在用的就是,

TextBox1.Text = nodeCurrent.FullPath; 

和输出我正在刚开g是这样的事情,

我的电脑\ C:\\的Documents and Settings \ Administrator的\桌面

这里我的电脑是根节点,我不需要,我要的是

C:\ Documents和Settings \管理员\桌面

图片加入

enter image description here

这里是我使用它

private void tvFolders_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) 
    { 
     //Populate folders and files when a folder is selected 
     this.Cursor = Cursors.WaitCursor; 

     //get current selected drive or folder 
     TreeNode nodeCurrent = e.Node; 
     string newPath = getFullPath(nodeCurrent.FullPath); 
     tbDirectory.Text = newPath; 


     //clear all sub-folders 
     nodeCurrent.Nodes.Clear(); 

     if (nodeCurrent.SelectedImageIndex == 0) 
     { 
      //Selected My Computer - repopulate drive list 
      PopulateDriveList(); 
     } 
     else 
     { 
      //populate sub-folders and folder files 
      PopulateDirectory(nodeCurrent, nodeCurrent.Nodes); 
     } 
     this.Cursor = Cursors.Default; 
    } 
+0

检查'吉姆Mischel's'的答案有,做同样的文章中的方法正如我所建议的那样。 – keyboardP 2011-12-30 15:21:13

回答

1

添加以下行的代码,它会删除重复的“\”路径

newPath = newPath.Replace("\\\\", "\\"); 
3

功能看起来对我来说,在该代码将不正是你想要的getFullPath方法。它剥去MyComputer\字符串并返回其余部分。写:

string newPath = getFullPath(nodeCurrent.FullPath); 
+0

我的问题的一半已解决,现在如何摆脱“C”之后出现的“C:\\”,因为我只需要一个,我怀疑是否可以将其删除,因为当我只点击驱动器c节点时我“C:/”但是当我去像文件它给我的子文件夹C:// Documents – 2011-12-30 15:24:05

+0

@TimeToThine:我没有看到任何代码,它会把它放在一个双反斜杠。你是否看到界面中显示的那些“\\”? – 2011-12-30 15:58:43

+0

我添加的图片先生,怎么看起来像 – 2011-12-30 16:05:35