C# 在树列表中上下移动节点
在我的项目中,我试图创建一个treelist用户控件,在按钮的帮助下(上下)上下移动节点,并使焦点节点在treelist中始终可见 C# 在上面的代码中,在没有父节点和子节点的情况下上下移动节点。在这个阶段,它工作得很好 如果用户当时关注根节点并单击“向上”按钮,则使用该索引获取lastnode索引值,我将selectednode设置为lastnode位置,即使用户从根节点单击“向上”按钮,它也会移动到最后,并使该节点在树列表中可见C# 在树列表中上下移动节点,c#,winforms,devexpress,treelist,C#,Winforms,Devexpress,Treelist,在我的项目中,我试图创建一个treelist用户控件,在按钮的帮助下(上下)上下移动节点,并使焦点节点在treelist中始终可见 C# 在上面的代码中,在没有父节点和子节点的情况下上下移动节点。在这个阶段,它工作得很好 如果用户当时关注根节点并单击“向上”按钮,则使用该索引获取lastnode索引值,我将selectednode设置为lastnode位置,即使用户从根节点单击“向上”按钮,它也会移动到最后,并使该节点在树列表中可见 但是,如果选择的节点作为特定父节点的第一个子节点,则在单击“向
但是,如果选择的节点作为特定父节点的第一个子节点,则在单击“向上”按钮时不会移动到最后一个子节点。如何做到这一点?这可能吗?给出一些想法。我找到了解决方案,在这里 C#
private void button1_Click(object sender, EventArgs e)
{
int LastNodeIndex = treeList1.GetNodeIndex(treeList1.Nodes.LastNode);
int targetNodeIndex = treeList1.GetNodeIndex(treeList1.FocusedNode.PrevNode);
if(targetNodeIndex==-1)
{
treeList1.SetNodeIndex(treeList1.FocusedNode, LastNodeIndex);
treeList1.MakeNodeVisible(treeList1.FocusedNode);
}
else
{
int nodeIndex = treeList1.GetNodeIndex(treeList1.FocusedNode);
treeList1.SetNodeIndex(treeList1.FocusedNode, targetNodeIndex);
treeList1.MakeNodeVisible(treeList1.FocusedNode);
}
}
private void button2_Click(object sender, EventArgs e)
{
int targetNodeIndex = treeList1.GetNodeIndex(treeList1.FocusedNode.NextNode);
int nodeIndex = treeList1.GetNodeIndex(treeList1.FocusedNode);
treeList1.SetNodeIndex(treeList1.FocusedNode, targetNodeIndex);
treeList1.MakeNodeVisible(treeList1.FocusedNode);
}
if(treeList1.FocusedNode.ParentNode!=null && foucsednodeindex == 0) // check its child node or not
{
int parentnodeindex = treeList1.GetNodeIndex(treeList1.FocusedNode.ParentNode);
int foucsedindex = treeList1.GetNodeIndex(treeList1.FocusedNode);
treeList1.SetFocusedNode(treeList1.FocusedNode.ParentNode);
int count = treeList1.FocusedNode.Nodes.Count;
treeList1.SetFocusedNode(treeList1.FocusedNode.NextVisibleNode);
treeList1.SetNodeIndex(treeList1.FocusedNode, count);
treeList1.MakeNodeVisible(treeList1.FocusedNode);
}