请问:如何通过button按钮控制TreeView控件节点的选择
我想实现点击button按钮后TreeView控件的当前选中的节点移到下一节点,请问如何实现 --------------------编程问答-------------------- 这个简单啊 直接获取当前选中节点的ID 然后再Click事件中重新邦定树啊! --------------------编程问答--------------------this.treeView1.SelectedNode = this.treeView1.Nodes[1].Nodes[1];--------------------编程问答-------------------- 这样很不行啊? --------------------编程问答-------------------- 就是treeview的selectedItem属性 --------------------编程问答--------------------
this.treeView1.Focus();
--------------------编程问答-------------------- 以上函數中的很多方法和屬性都沒有啊??
#region TreeView节点上下移动
/// <summary>
/// treeview子节点上下移动
/// </summary>
/// <param name="ToIndex"></param>
/// <param name="treeNode"></param>
/// <param name="tvname"></param>
/// <returns></returns>
private TreeNode MoveTo(int ToIndex, TreeNode treeNode)
{
Object NewNode = treeNode.Clone();
treeNode.Parent.Nodes.Insert(ToIndex, (TreeNode)NewNode);
treeNode.Remove();
return (TreeNode)NewNode;
}
/// <summary>
/// treeview根节点上下移动
/// </summary>
/// <param name="ToIndex"></param>
/// <param name="treeNode"></param>
/// <param name="tvname"></param>
/// <returns></returns>
private TreeNode MoveToRoot(int ToIndex, TreeNode treeNode, TreeView tvname)
{
Object NewNode = treeNode.Clone();
tvname.Nodes.Insert(ToIndex, (TreeNode)NewNode);
treeNode.Remove();
return (TreeNode)NewNode;
}
public void TreeviewUp(TreeView tv)
{
if (tv.SelectedNode != null && tv.SelectedNode.Level == 0)
{
int oldindex = tv.SelectedNode.Index;
TreeNode oldnode = tv.Nodes[oldindex];
tv.BeginUpdate();
TreeNode nNode = MoveToRoot(oldnode.Index - 1, oldnode, tv);
tv.EndUpdate();
tv.SelectedNode = nNode;
tv.Focus();
}
else
{
if (tv.SelectedNode != null && tv.SelectedNode.Parent != null)
{
int oldindex = tv.SelectedNode.Index;
TreeNode oldnode = tv.SelectedNode.Parent.Nodes[oldindex];
tv.BeginUpdate();
TreeNode nNode = MoveTo(oldnode.Index - 1, oldnode);
tv.EndUpdate();
tv.SelectedNode = nNode;
tv.Focus();
}
}
}
public void TreeviewDown(TreeView tv)
{
if (tv.SelectedNode != null && tv.SelectedNode.Level == 0)
{
int oldindex = tv.SelectedNode.Index;
TreeNode oldnode = tv.Nodes[oldindex];
tv.BeginUpdate();
TreeNode nNode = MoveToRoot(oldnode.Index + 2, oldnode, tv);
tv.EndUpdate();
tv.SelectedNode = nNode;
tv.Focus();
}
else
{
if (tv.SelectedNode != null && tv.SelectedNode.Parent != null)
{
int oldindex = tv.SelectedNode.Index;
TreeNode oldnode = tv.SelectedNode.Parent.Nodes[oldindex];
tv.BeginUpdate();
TreeNode nNode = MoveTo(oldnode.Index + 2, oldnode);
tv.EndUpdate();
tv.SelectedNode = nNode;
tv.Focus();
}
}
}
#endregion
--------------------编程问答-------------------- 就用TreeviewUp和TreeviewDown方法,传Treeview对象当作参数
补充:.NET技术 , C#