日期:2014-05-18  浏览次数:21095 次

treeview目录展开问题
我用的是VS2003,我现在碰到的情况是:   左边有个树目录,右边有个表,树目录

里有很多级,在右边里选个值,树目录会自动打开所选值的节点。。就像windows的帮

助的功能一样。。。   希望有资料的朋友发到资料到我邮箱,问题解决,可以再给分!

邮箱:wuxingmaxail@163.com

------解决方案--------------------
asp.net 2.0 的 TreeView 即是如此实现

TreeView 具有 TreeNode FindNode(string valuePath) 方法

TreeNode 具有 Collapse 和 Expand 方法

思路既是如此 ...
------解决方案--------------------
/// <summary>
/// 建树
/// </summary>
/// <param name= "father "> 父号码 </param>
protected void treeNode(string father, TreeNode fatherNode)
{
if (father != " ")
{
DataRow[] rows = dt.Select( "Father= ' " + father + " ' ", "CreateDate asc ");
if (0 != rows.Length)
{
foreach (DataRow row in rows)
{
TreeNode newTreeNode = new TreeNode();
newTreeNode.Text = row.ItemArray[0].ToString() + "( " + row.ItemArray[1].ToString() + ") ";
newTreeNode.Value = row.ItemArray[0].ToString();
newTreeNode.Expanded = false;
if (onlyOne)
{
this.tv_Help.Nodes.Add(newTreeNode);
fatherNode = this.tv_Help.Nodes[0];
}
else
{
fatherNode.ChildNodes.Add(newTreeNode);
}
DataRow[] rs = dt.Select( "father= ' " + newTreeNode.Value + " ' ");
if (0 != rs.Length && !onlyOne)
{
treeNode(row.ItemArray[0].ToString(), newTreeNode);
}
if (onlyOne)
{
onlyOne = false;
treeNode(row.ItemArray[0].ToString(), fatherNode);
}
}
}
else
{
return;
}
}
else
{
TreeNode newTreeNode = new TreeNode();
newTreeNode.Text = "业务类型 ";
newTreeNode.Value = "HOWIN ";
this.tv_Help.Nodes.Add(newTreeNode);
fatherNode = this.tv_Help.Nodes[0];
onlyOne = false;
treeNode( "HOWIN ",fatherNode);
}
}
public void SetAllNodeText(TreeNodeCollection tnc)
{
foreach (TreeNode node in tnc)
{
if (node.ChildNodes.Count == 0)
{
node.NavigateUrl = "javascript:goback( ' " + node.Value + " '); ";

}
if (node.ChildNodes.Count != 0)
{
SetAllNodeText(node.ChildNodes);
}
}
}