Procedura: individuare il nodo di TreeView scelto (Windows Form)
Aggiornamento: novembre 2007
Quando si utilizza il controllo TreeView Windows Form, un'operazione comune consiste nello stabilire quale nodo è stato scelto e nel fornire la risposta appropriata.
Per stabilire il nodo di TreeView scelto
Utilizzare l'oggetto EventArgs per restituire un riferimento all'oggetto nodo scelto.
Per determinare il nodo scelto, verificare la classe TreeViewEventArgs, che contiene i dati relativi all'evento.
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); }
Nota:
In alternativa è possibile utilizzare l'argomento MouseEventArgs dell'evento MouseDown o MouseUp per ottenere i valori delle coordinate X e Y dell'oggetto Point in cui è stato fatto clic. Utilizzare quindi il metodo GetNodeAt del controllo TreeView per determinare il nodo scelto.