PDA

View Full Version : [VB.NET] Aggiungere un nodo figlio al TreeView


race2
27-11-2003, 22:12
Mi funziona tutto per la visualizzazione e la raccolta dei dati, solamente che manca l'ultimo dettaglio,

voglio creare l'evento " TreeView1.AfterSelect " e poi " TreeView1.BeforeExpand " ma sensa un nodo figlio non posso farlo, come faccio per creare un figlio li ????


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

TreeView1.BeginUpdate()

TreeView1.Nodes.Clear()

oConn.Open()

Dim oComm As New SqlCommand("SELECT ID_Pratica FROM Pratiche ORDER BY ID_Pratica ASC", oConn)

Dim oRead As SqlDataReader = oComm.ExecuteReader

While oRead.Read()

Dim n1 As New MyNodes(oRead("ID_Pratica"), "Pratica ")

n1.Text = n1.Label + " " + n1.ID

TreeView1.Nodes.Add(n1)

'qui' il nodo figlio # finto #

End While

oConn.Close()

TreeView1.EndUpdate()

End Sub

Public Class MyNodes : Inherits TreeNode

Public ID, Label As String

Public Sub New(ByVal _ID_ As String, ByVal Testo As String)

ID = _ID_

Label = Testo

End Sub

Public Overrides Function ToString() As String

Return ID + " " + Label

End Function

End Class