如题.大大们帮忙.
解决方案 »
- C# richTextBox的Key_UP,Key_Down,Key_left,Key_right事件
- Excel问题(有图)
- 独立DataTable 使用时的问题
- 怎么调整DATATABLE的列宽呢
- C#中执行Insert出错的问题,请大家帮帮忙(急)!
- 怎样用WindowsMediaPlayer控件播放MP3
- 【求助】请问如何向未知IP的server端 发送socket请求建立连接?多谢
- 急呀,明天交作业了,帮个忙,关于C#调用C++写的DLL的~~~
- throw的问题?请指教.
- 请高手请一段JAVA代码翻译为C#, MD5加密部分
- .net的两个简单问题
- VS2005有取最小整數的函數嗎?
写个递归查找
找到后调用TreeNode的展开方法
{
// 获取DataItem
CFoodCatalogGB catalog = e.Node.DataItem as CFoodCatalogGB;
if (catalog != null)
{
// 设置绑定方式
e.Node.Text = catalog.Name;
e.Node.Value = catalog.ID.ToString();
}
// 比较节点值并做出判断
if(catalog.Name=="The value you wanted")
{
//
// 在这里添加希望对目标节点进行的操作。
//
e.Node.Parent.Expand();
}
}
private TreeNode GetTreeNode(TreeNode node)
{
if (node.Text == "test")
{
return node;
}
if (node.Nodes.Count > 0)
{
foreach (TreeNode temp in node.Nodes)
{
TreeNode t = GetTreeNode(temp);
if (t != null)
{
return t;
}
}
}
return null;
}
TreeNode t = GetTreeNode(tv.Nodes[0]);
if (t != null)
{
t.Expand();
}
if (t != null)
{
t.Expand();
}不能简单的写成t.expand();吧!t还有parent t.parent可能还有parent 好像又要用递归去展开了
{
t.Expand();
TreeNode parent = t.Parent;
while (parent != null)
{
parent.Expand(); if (parent.Parent != null)
{
parent = parent.Parent;
}
else
{
break;
}
}
}