gpt4 book ai didi

c# - 在 Windows 应用程序中以编程方式选择 TreeView 中的节点

转载 作者:可可西里 更新时间:2023-11-01 09:17:40 24 4
gpt4 key购买 nike

我已经加载了一个 TreeView 。我想遍历 TreeView 节点并展开并选择一个节点。展开工作正常。但选择一个节点不起作用。

private void Traverse(TreeNodeCollection nodes, string findtext) 
{
foreach (TreeNode node in nodes)
{
if (node.Text.ToString().Trim() == findtext)
{
node.Expand();
node.TreeView.SelectedNode = node.NextNode;

//tvwStructureTree.SelectedNode = this.tvwStructureTree.Nodes[node.Index];
//Select a node in Treeview tvwStructureTree But not working
tvwStructureTree.SelectedNode = node;
node.TreeView.Focus();
}
Traverse(node.Nodes, findtext);
}

}

它在 Windows 应用程序中。

最佳答案

不太确定您的问题是什么。 TreeView.SelectedNode Property是正确的属性。

When you set this property, the specified node is scrolled into view and any parent nodes are expanded so that the specified node is visible.

When the parent node or any ancestor node of the selected node is collapsed either programmatically or through user action, the collapsed node becomes the selected node.

确保 node.TreeView 是正确的 TreeView 实例。

node.TreeView.SelectedNode = node.NextNode;  

TreeView.HideSelection Property是另一个可能对您有用的属性。

When this property is set to false, selected nodes in the TreeView control remain highlighted in a different color than the current selection color when the TreeView control loses focus. You can use this property to keep items that are selected by the user visible when the user clicks a different control on the form or moves to a different window.

关于c# - 在 Windows 应用程序中以编程方式选择 TreeView 中的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7736457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com