treeView 控件的问题 好像没听说TreeView有这个功能 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try:private TreeNode GetNodeByPath(TreeNode root,string path){ int index = path.IndexOf(this.TreeView1.FullPath); string s ; if(index != -1) { s = path.Substring(0,index); path = path.Substring(index + 1); foreach(TreeNode node in root.Nodes) if(node.Text == s) return GetNodeByPath(node,path); } else foreach(TreeNode node in root.Nodes) if(node.Text == path) return node; return null;//节点不存在}ps:为什么不用一个TreeNode来存放节点呢? to:FileNewExit((呵呵)) ps:为什么不用一个TreeNode来存放节点呢?这句话什么意思啊?你有更好的主意吗? 重绘前用viewstate保存,重绘时恢复 我的意思是:你知道了Country\Region\State节点(比如是node),你就用一个TreeNode来保存它呀 TreeNode currentNode = node;以后,你就持有这个节点对象了.不知道我理解(你的意思)得对不对:( 刚好我做过的,给你代码直接能用 public TreeNode FindNodeOnPath(TreeNodeCollection tn, string nodepath) { string str1 = null; string str2 = null; if(tn.Count < 1) return null; TreeNode TempTn = null; int pos = nodepath.IndexOf('\\' ,0 ); if(pos > 0) { //当前要找的结点 str1 = nodepath.Substring(0, pos); //下一级目录的结点 str2 = nodepath.Substring(pos + 1); } else str1 = nodepath; //从当前一级树目录中查找结点 for(int i = 0; i < tn.Count; i++) { //找到了 if(tn[i].Text == str1) { TempTn = tn[i]; //是要找树结点的最终位置 if(str2 == null) break; else { //继续往下查找 TreeNode tnd = FindNodeOnPath(tn[i].Nodes, str2); if(tnd != null) TempTn = tnd; } break; } } //没找到返回空 return TempTn; } 功能说明:参数是树根结点的结点集合,上次结点的fullpath实现了在树中定位到fullpath描述的结点,并返回这个结点,如果没找到则返回找到的它的父结点,什么没找到则为空。使用场合记录上次退出时用户最后一次点击的树结点,在一打开这个树时,就将当前结点定位到它上面,并展开树。 想用MVC3做一个团购网站 怎么把本地EXCEL里的数据导入到远程服务器的SQL里 实在是搞不懂IAsyncResult.AsyncWaitHandle.WaitOne(),到底起什么作用?看例子看不明白。 谁能帮我???? winfrom功能请教 求 sharpdevelope 完整代码我感觉下的不是完整的代码! 数组问题 doublel类型的数据的转换 为什么在C#中没有找到关于线程的概念? 从C#对中文的支持想到对微软的一己之见 有什么办法将COLOR里的所有颜色全部取到一个数组里? 有关html在线编辑器的问题
int index = path.IndexOf(this.TreeView1.FullPath);
string s ;
if(index != -1)
{
s = path.Substring(0,index);
path = path.Substring(index + 1);
foreach(TreeNode node in root.Nodes)
if(node.Text == s)
return GetNodeByPath(node,path);
}
else
foreach(TreeNode node in root.Nodes)
if(node.Text == path)
return node;
return null;//节点不存在
}
ps:为什么不用一个TreeNode来存放节点呢?
ps:为什么不用一个TreeNode来存放节点呢?
这句话什么意思啊?你有更好的主意吗?
你知道了Country\Region\State节点(比如是node),你就用一个TreeNode来保存它呀
TreeNode currentNode = node;以后,你就持有这个节点对象了.不知道我理解(你的意思)得对不对:(
public TreeNode FindNodeOnPath(TreeNodeCollection tn, string nodepath)
{
string str1 = null;
string str2 = null;
if(tn.Count < 1)
return null;
TreeNode TempTn = null;
int pos = nodepath.IndexOf('\\' ,0 );
if(pos > 0)
{
//当前要找的结点
str1 = nodepath.Substring(0, pos);
//下一级目录的结点
str2 = nodepath.Substring(pos + 1);
}
else
str1 = nodepath;
//从当前一级树目录中查找结点
for(int i = 0; i < tn.Count; i++)
{
//找到了
if(tn[i].Text == str1)
{
TempTn = tn[i];
//是要找树结点的最终位置
if(str2 == null)
break;
else
{
//继续往下查找
TreeNode tnd = FindNodeOnPath(tn[i].Nodes, str2);
if(tnd != null)
TempTn = tnd;
}
break;
}
}
//没找到返回空
return TempTn;
}
参数是树根结点的结点集合,上次结点的fullpath实现了在树中定位到fullpath描述的结点,并返回这个结点,如果没找到则
返回找到的它的父结点,什么没找到则为空。使用场合
记录上次退出时用户最后一次点击的树结点,在一打开这个树时,就将当
前结点定位到它上面,并展开树。