많은 노드가있는 Treeview가 있습니다. 노드를 전환하면 트리 뷰의 스크롤 막대가 아래쪽으로 설정됩니다.트 리뷰는 스크롤 위치를 유지합니다.
전환 된 노드를 계속 표시하려면 node.EnsureVisible()
을 사용하십시오. 하지만 최종 사용자를 혼란스럽게하기 때문에이 방법이 맘에 들지 않습니다.
은 그래서 더보고 지금은 여기에 제공되는 코드를 사용하고, 트 리뷰의 내용이 스크롤되지 않습니다
Maintain scroll position of treeview
이 코드의 문제를. 스크롤 바가 올바른 위치에 있지만 내용은 아무 것도하지 않습니다. 스크롤 막대를 클릭 할 때까지 (스크롤하지 않습니다) 내용이 표시됩니다.
그래서, 내가 원하는 것은 treenode가 전환 될 때 스크롤 위치를 유지하려고하는 것입니다.
노드를 전환하는 코드입니다. 이 경우에는 노드가 아래쪽에 있습니다. 이 같은 기능의 모양을
// Check a node is selected
if (tvCategories.SelectedNode == null)
return;
// The first node may not be moved
if (IsNewRootCategorySelected())
return;
Point ScrollPos = GetTreeViewScrollPos(tvCategories);
// Declare and instantiate the parent node
TreeNodeCollection parent = null;
if (tvCategories.SelectedNode.Parent == null)
parent = tvCategories.Nodes;
else
parent = tvCategories.SelectedNode.Parent.Nodes;
TreeNode selectedNode = tvCategories.SelectedNode;
int index = selectedNode.Index;
// Check there's a next node at the same level
if (tvCategories.SelectedNode.NextNode == null)
{
// Check if the parent node has a next node
if (tvCategories.SelectedNode.Parent != null && tvCategories.SelectedNode.Parent.NextNode != null)
{
// get the destination parent
TreeNode destParent = selectedNode.Parent.NextNode;
// remove selected node from tree view
parent[index].Remove();
// If selected node is a category, add the node to the first index
if (selectedNode.Tag is Category)
{
destParent.Nodes.Insert(0, selectedNode);
}
// If selected node is a question, add node below last category
if (selectedNode.Tag is Question)
{
int newIndex = 0;
// Loop through collection to find last category
for (int i = destParent.Nodes.Count - 1; i >= 0; i--)
{
if (destParent.Nodes[i].Tag is Category)
{
newIndex = i + 1;
break;
}
}
destParent.Nodes.Insert(newIndex, selectedNode);
}
selectedNode.Expand();
}
}
else
{
// Switch nodes in same level
tvCategories.BeginUpdate();
_loading = true;
if (selectedNode.Tag is Category)
{
// Only switch category downwards when next node is a catgory
if (selectedNode.NextNode.Tag is Category)
{
// Perform switch
TreeNode switchNode = parent[index + 1];
parent[index + 1].Remove();
parent[index].Remove();
parent.Insert(index, switchNode);
parent.Insert(index + 1, selectedNode);
}
else if (selectedNode.NextNode.Tag is Question)
{
// Make the switch to another node below
if (selectedNode.Parent.NextNode != null)
{
// Parent is always a category
TreeNode categoryParent = selectedNode.Parent.NextNode;
// Remove selected node from current parent
parent.Remove(selectedNode);
// Insert selected node
categoryParent.Nodes.Insert(0, selectedNode);
}
}
}
if (selectedNode.Tag is Question)
{
if (selectedNode.NextNode.Tag is Question)
{
// Perform switch
TreeNode switchNode = parent[index + 1];
parent[index + 1].Remove();
parent[index].Remove();
parent.Insert(index, switchNode);
parent.Insert(index + 1, selectedNode);
}
}
}
tvCategories.EndUpdate();
// Set focus
tvCategories.Focus();
tvCategories.SelectedNode = selectedNode;
SetTreeViewScrollPos(tvCategories, ScrollPos);
"노드를 전환합니다."그게 무슨 뜻입니까? –
노드를 전환하는 코드가 있습니다. 시작 지점에서 내 편집보기 – Martijn