如何:判斷按下哪個 TreeView 節點 (Windows Form)
使用 Windows Forms 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); }