| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2769 人关注过本帖
标题:[求助]怎么获取TreeView的结点的路径
取消只看楼主 加入收藏
leely_lly
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-4-11
收藏
 问题点数:0 回复次数:2 
[求助]怎么获取TreeView的结点的路径

C#中,我想在结点上点击鼠标右键获得该结点的路径,应该怎么写代码?谢谢!

搜索更多相关主题的帖子: 结点 TreeView 路径 获取 
2007-04-13 11:08
leely_lly
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-4-11
收藏
得分:0 

呵呵,谢谢,可是我还是不太懂,我没有用到数据库.就只是做了一个本机文件的treeView,现在就是想在结点上右击,弹出上下文菜单,获得被点击的结点的路径,以便对其进行一些别的操作.

2007-04-13 11:41
leely_lly
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-4-11
收藏
得分:0 

恩,好方法,可是我对文件树的加载是这样进行的,以下是我的代码,怎么才能实现我的功能呢.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace Compress
{
public partial class FormFile : Form
{
private string nodeName;
public FormFile()
{
InitializeComponent();
}

private DirectoryInfo folder;


private void FormFile_Load(object sender, EventArgs e)
{
LoadTree();
}


private void LoadTree()
{
DirectoryInfo directory;

//clear the tree
//treeExplore.Nodes.Clear();


//Loop through the drive letter and find the available drive

foreach (string drive in Environment.GetLogicalDrives())
{
try
{
// get the directory information for this path
directory = new DirectoryInfo(drive);

//if the retrived directory is valid ,add it to the tree view
if (directory.Exists == true)
{
TreeNode newNode = new TreeNode(directory.FullName);
treeExplore.Nodes.Add(newNode);

//add the new node to the root level
GetSubDirectories(newNode);

}
}

catch
{
return;
}
}
}


private void GetSubDirectories(TreeNode parent)
{
DirectoryInfo directory;
try
{
if (parent.Nodes.Count == 0)
{
directory = new DirectoryInfo(parent.FullPath);
foreach (DirectoryInfo dir in directory.GetDirectories())
{
TreeNode newNode = new TreeNode(dir.Name);
parent.Nodes.Add(newNode);
}

}
foreach (TreeNode Node in parent.Nodes)
{
if (Node.Nodes.Count == 0)
{
directory = new DirectoryInfo(Node.FullPath);
foreach (DirectoryInfo dir in directory.GetDirectories())
{
TreeNode newnode = new TreeNode(dir.Name);
Node.Nodes.Add(newnode);
}
}
}
}
catch
{
return;
}
}


private void treeExplore_AfterSelect(object sender, TreeViewEventArgs e)
{
DirectoryInfo dirInfo = new DirectoryInfo(e.Node.FullPath);
listExplorer.Items.Clear();
if (dirInfo.Exists)
{
FileInfo[] fileInfo = dirInfo.GetFiles();
foreach (FileInfo info in fileInfo)
{
ListViewItem item = new ListViewItem();
item = listExplorer.Items.Add(info.Name);
item.SubItems.Add(info.LastAccessTime.ToString());
item.SubItems.Add(info.Length.ToString());
}
}



private void onMouseDown(object sender, MouseEventArgs e)
{
TreeNode newSelectedNode = treeExplore.GetNodeAt(e.X, e.Y);
if (newSelectedNode != null)
{
treeExplore.SelectedNode = newSelectedNode;
treeExplore.SelectedNode.ContextMenuStrip = contextMenuStrip; //哈哈,终于找到你了!
}

if (e.Button == MouseButtons.Right)
{
treeExplore.SelectedNode = treeExplore.GetNodeAt(e.X, e.Y);
contextMenuStrip.Visible = true;
contextMenuStrip
MessageBox.Show("abc");
}

}


   private void compressMenuItem_Click(object sender,
                TreeNodeMouseClickEventArgs e) //compressMenuItem是contextmenu的列表
{                              
string[] FileProperties = new string[2];          
FileProperties[0] = "???";   //待解压的文件 这是最关键的,怎么才是正确获的文件的路径
FileProperties[1] = "???";//解压后放置的目标目录
ZipClass Zc = new ZipClass();            //调用一个压缩函数,实现对文件的压缩,
Zc.ZipFileMain(FileProperties);  //函数的参数是文件的路径,现在的问题是怎么取的文件的路径
}

}

}

[此贴子已经被作者于2007-4-16 11:22:26编辑过]

2007-04-16 11:10
快速回复:[求助]怎么获取TreeView的结点的路径
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037569 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved