单击树中的新节点时,如何获取旧节点?

时间:2018-01-22 18:05:22

标签: c# winforms treeview

我正在查看TreeView events而没有看到它。

例如,BeforeSelect显示新节点:

private void myTreeView_BeforeSelect(Object sender, TreeViewCancelEventArgs eventArgs)
{
    System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
    string node = "\tNode: " + eventArgs.Node; // This is the new node
    string action = "\tAction: " + eventArgs.Action; // ByMouse
    string cancel = "\tCancel: " + eventArgs.Cancel; // False
}

1 个答案:

答案 0 :(得分:3)

您可以使用((TreeView) sender).SelectedNode

来获取它
private void myTreeView_BeforeSelect(object sender, TreeViewCancelEventArgs eventArgs)
{
    System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
    string node = "\tNode: " + eventArgs.Node; // This is the new node
    string action = "\tAction: " + eventArgs.Action; // ByMouse
    string cancel = "\tCancel: " + eventArgs.Cancel; // False

    //Get the current selected node/old node after the select processed
    var oldNode = ((TreeView) sender).SelectedNode;
}