【发布时间】:2020-07-09 09:42:01
【问题描述】:
在树形视图控件中,我默认的所需键盘行为是使用左/右箭头键折叠/展开,使用上/下箭头键遍历可见节点不使用 折叠或展开它们。
但由于某些奇怪的原因,以下代码在使用向上/向下箭头键选择节点时会自动折叠/展开节点:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
// This line produces strange auto-collapse/expand behaviour,
// but is needed in order to correctly set the image of the selected node.
// If I comment this line out, then keyboard input produces the desired behaviour.
treeView1.SelectedImageIndex = e.Node.ImageIndex;
}
- 为什么会这样?
- 如何预防?
【问题讨论】: