Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview Question

Status
Not open for further replies.

jpinto

Technical User
Dec 12, 2003
75
PT
I've a treeview on my form that as a Parent node "Familia" and a child node "Ocorrencias". Here's the code:

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
 
Set the Parent node's SelectedImageIndex property to the same value as its ImageIndex property - in this case, 0.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top