单击 dataGridView 的任何部分后,Treeview 节点选择发生更改

Treeview node selection changed after clicking on any potion of the dataGridView

我在用户控件的左侧有一个 treeview,在同一个用户控件中有一个 dataGridView。我只是简单地点击 treeviewnode 并且通常它会被选中但是在那之后当我在 DataGridView 的任何部分按下鼠标时,我发现 treenode's 突出显示的部分消失了它变得未被选中。

这种情况不会发生在任何其他控件上。 我怎样才能阻止这种情况发生?

TreeView.HideSelection 属性 设置为 false:

Gets or sets a value indicating whether the selected tree node remains highlighted even when the tree view has lost the focus.

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.