Allora, mi trovo sulla form DettagliDocumento (dove ho il treeview: TreeViewAllegati)
All'evento NuovoAllegato.Click
codice:
Private Sub NuovoAllegato_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NuovoAllegato.Click
Dim FormAllegati As New Allegato
FormAllegati.MdiParent = InformationArchive
FormAllegati.WindowState = FormWindowState.Normal
FormAllegati.StartPosition = FormStartPosition.CenterScreen
FormAllegati.Action = 1
FormAllegati.ID_Informazione_Allegato = ID_Informazione
FormAllegati.Show()
End Sub
Adesso mi trovo sul form Allegato:
Inserisco il mio nuovo allegato e salvo il riferimento sul db. Adesso vorrei aggiornare il mio treeview richiamando una sub dichiarata public che si trova sempre nel form DettagliDocumento:
codice:
DettagliDocumento.VisualizzaDettagli()
Ecco la Sub VisualizzaDettagli:
codice:
Dim NodeAllegati As TreeNode
Me.TreeViewAllegati.AllowDrop = True
TreeViewAllegati.BeginUpdate()
TreeViewAllegati.SelectedNode = Nothing
TreeViewAllegati.Nodes.Clear()
TreeViewAllegati.Enabled = True
OpenSqlConnection()
Dim QueryAllegati As System.Data.SqlClient.SqlDataReader = CreateCommandReader("SELECT * FROM Allegati WHERE ID_Informazione=" & Me.ID_Informazione)
While QueryAllegati.Read
NodeAllegati = TreeViewAllegati.Nodes.Add(QueryAllegati("Titolo"))
NodeAllegati.Name = QueryAllegati("ID_Allegato")
End While
QueryAllegati.Close()
TreeViewAllegati.EndUpdate()
CloseSqlConnection()
Il problema è che non si aggiorna niente... ma l'interprete esegue correttamente tutte le righe!!