I've a treeview on my form that as a Parent node "Familia" and a child node "Ocorrencias". Here's the code:
I'm putting an image to the parent node (index=0) and one to the child node (index=1) from an imagelist.
My problem is that when I click on the parent node, the image changes from the index 0 to the index 1, and when I click on other parent the image returns to the normal index 0 image.
Can annyone help me please?
Thanks,
João Pinto
Code:
Private Sub frmListaOcorrenciasTree_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x, y As Integer
Dim NomeFamilia, NomeOcorrencia As String
Dim OcorrenciaNode As TreeNode
trvOcorrencias.Nodes.Clear()
trvOcorrencias.ImageList = ImageListTree
trvOcorrencias.ImageIndex = 0
Me.ListaOcorrenciasQueryTableAdapter.Fill(Me.ReportItDataSet.ListaOcorrenciasQuery)
OcorrenciaBoolean = False
conexao()
sSQL = "SELECT * FROM [Familias]"
da = New OleDb.OleDbDataAdapter(sSQL, con)
ds.Clear()
da.Fill(ds, "Familias")
For x = 0 To ds.Tables("Familias").Rows.Count - 1
NomeFamilia = ds.Tables("Familias").Rows(x).Item("Familia").ToString
trvOcorrencias.Nodes.Add(NomeFamilia)
sSQL2 = "SELECT [Descriçao] FROM [Ocorrencias] WHERE [Familia]='" & NomeFamilia & "' GROUP BY [Descriçao] ORDER BY [Descriçao] ASC"
da2 = New OleDb.OleDbDataAdapter(sSQL2, con)
ds2.Clear()
da2.Fill(ds2, "Ocorrencias")
For y = 0 To ds2.Tables("Ocorrencias").Rows.Count - 1
NomeOcorrencia = ds2.Tables("Ocorrencias").Rows(y).Item("Descriçao").ToString
OcorrenciaNode = trvOcorrencias.Nodes(x)
OcorrenciaNode.Nodes.Add(NomeOcorrencia)
OcorrenciaNode.ImageIndex = 1
Next
Next
con.Close()
End Sub
I'm putting an image to the parent node (index=0) and one to the child node (index=1) from an imagelist.
My problem is that when I click on the parent node, the image changes from the index 0 to the index 1, and when I click on other parent the image returns to the normal index 0 image.
Can annyone help me please?
Thanks,
João Pinto