如何:确定被单击的 TreeView 节点(Windows 窗体)
使用 Windows 窗体 TreeView 控件时,一个常见的任务是确定单击了哪个节点,并相应地予以响应。
确定单击了哪个 TreeView 节点
使用 EventArgs 对象返回对已单击节点对象的引用。
通过检查 TreeViewEventArgs 类(它包含与事件有关的数据)来确定单击了哪个节点。
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect ' Determine by checking the Node property of the TreeViewEventArgs. MessageBox.Show(e.Node.Text) End Sub
protected void treeView1_AfterSelect (object sender, System.Windows.Forms.TreeViewEventArgs e) { // Determine by checking the Text property. MessageBox.Show(e.Node.Text); }
private: void treeView1_AfterSelect(System::Object ^ sender, System::Windows::Forms::TreeViewEventArgs ^ e) { // Determine by checking the Text property. MessageBox::Show(e->Node->Text); }