none
Save changes in TreeNodes before exit RRS feed

  • Question

  • Hi all

    I try to make program for library witch use treenodes

    I use this code to load items to treenodes

    'lets conecct to our database
            Try
                Dim Cadena As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\RecursosEmpresariales.mdb;User ID=Admin;Password="
                'Dim Cadena As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\RecursosEmpresariales.mdb;User ID=Admin;Password="
                oleconexion = New OleDb.OleDbConnection(Cadena)
            Catch
                MsgBox(Err.Description)
                Exit Sub
            End Try
            '''''''''''''''''''''''''''''
            'just in case..lets clear the tree view
            Tree.Nodes.Clear()
    
            oleconexion.Open()
    
            'get the data..
            daCategoria = New OleDb.OleDbDataAdapter("select Categoria from Categoria", oleconexion)
            'initialize the data set
            dsgeneral = New DataSet()
    
            'now whe fill the dataset with the result of the dacategoria
            daCategoria.Fill(dsgeneral, "Categoria") 'l
    
    
            Dim I%, j%, Categoria$, Cargo$
    
            'lets count all the rows we got in order to add them to the control
            'one by one...
            For I = 0 To dsgeneral.Tables("Categoria").Rows.Count - 1
    
                Categoria = dsgeneral.Tables("Categoria").Rows(I).Item("Categoria").ToString
    
                'we add the items one by one...
                Tree.Nodes.Add(Categoria)
                Tree.Nodes(I).ImageIndex = 0
                'now that we are in xx position...lets say the 3rd position(remember that the tables in the dataset
                'begin with position 0)we get all the records from the Cargo table that belong to the categoria field
                'so we add them as childs to the respective parent node in the control...
    
                daCargo = New OleDb.OleDbDataAdapter("select * from Cargo where categoria='" & Categoria & "'", oleconexion)
    
                daCargo.Fill(dsgeneral, "Cargo") 'l
                'clear the erronuos data
                dsgeneral.Tables("Cargo").Clear()
                'fill again the data with the new query
                daCargo.Fill(dsgeneral, "Cargo") 'l
    
                For j = 0 To dsgeneral.Tables("Cargo").Rows.Count - 1
                    'once we have the records we fill the respective child node in the control
    
                    Cargo = dsgeneral.Tables("Cargo").Rows(j).Item("Cargo").ToString
                    Dim CargoNode As TreeNode
                    CargoNode = Tree.Nodes(I)
    
                    CargoNode.Nodes.Add(Cargo)
                    'asigne a image
    
    
                    'then we expand the nodes so we can show the child nodes
                    CargoNode.Expand()
    
    
                Next
    
                'now ge go to the next row in the categoria table..
            Next
    
            'after fill the control..lets fill the progress bar just to advice the
            'user that the data is loading...
            oleconexion.Close()
    

    but how I make program save changes before exit ?????

    thank you


    I must Win
    Sunday, September 4, 2011 3:19 PM

Answers