从Tree选择Node的事件,刷新List的时候,把这个TreeNode的路径信息存到ListView.Tag里面不就可以了。这样你选择ListView的Item的时候,这个路径可以从ListView.Tag里面得到,然后拼上你点击的Item就是完整的路径了。
首先在响应treeview中Node鼠标单击事件的时候将这个路径保存到listview的Tag属性中
private void treeExplorer_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
//MessageBox.Show(e.Node.FullPath);
this.listExplorer.Tag = e.Node.FullPath;
//MessageBox.Show(this.listExplorer.Tag.ToString());
}
然后在listview中项的双击事件中获得该tag+选中该项的名字this.listExplorer.Items[0].Text即取得该选中项的完整路径
private void listExplorer_MouseDoubleClick(object sender, MouseEventArgs e)
{
//this.listExplorer.SelectedItems;
string Root = this.listExplorer.Tag.ToString()+@"/"+this.listExplorer.Items[0].Text.ToString();
//MessageBox.Show(Root);
}
其实我发现还有一个问题那就是我点击了listview中的文件夹后,继续点击该文件夹下面的文件夹就会有异常,正在处理中。