2012-01-31 79 views
0

所以我也跟着MS文章http://msdn.microsoft.com/en-us/library/ms171645.aspxC#资源管理器界面中选择文件

这是使用ListView和TreeView控件使用设计器创建一个资源管理器风格的界面。

现在它会在文件夹左侧加载一个树形视图,然后在显示器上显示列表视图。

现在,当我在右侧窗格中选择一个文件夹或文件时,我想获取完整的文件路径。 Howerver,当我做listview.selectIndex [0]时,它只提供给我名字。我相信这是因为左手树视图正在被驱散。

这是否有意义?我想要完成的是选择文件,它为我提供了完整的路径。

对此提出建议?

回答

1

当我做listview.selectIndex [0]时,它只提供给我名字。我相信这是因为左手树视图正在被驱散。

正确。您需要将TreeView控件的路径与ListView控件中的项目名称组合起来。

示例代码(其中TreeView1是你的左手TreeView控制和ListView1是你的右手ListView控制):

String GetSelectedItemPath() 
{ 
    String path = String.Empty; 

    // See if a node is selected in the TreeView 
    TreeNode selectedNode = TreeView1.SelectedNode; 
    if (selectedNode != null) 
    { 
     // Also check that an item is selected in the ListView 
     ListViewItem item = ListView1.SelectedItems[0]; 
     if (item != null) 
     { 
      // Build the full path to the selected item. 
      path = selectedNode.FullPath + TreeView1.PathSeparator + item.Text; 
     } 
    } 

    return path; 
} 
+0

感谢让我给那些尝试。 – user1158745 2012-01-31 21:13:04

0

如果在右边看到在左边选择的文件夹的内容,我会说,是的,你是对的。要获得在RIGHT平移中选择的文件夹的完整路径,您需要连接在TreeView(左)和folder name(右)上选择的文件夹的路径。

相关问题