Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: jack06 en 3 Octubre 2016, 01:59 am



Título: Agrupar datos de una BD en un TreeView VB 6.0
Publicado por: jack06 en 3 Octubre 2016, 01:59 am
Buenos amigos,

Pues bien, la duda que tengo es de como poder llenar unos datos que tengo una BD y cargarlos en un TreeView, ya eh logrado cargar los datos en el control TreeView lo que no logro es agruparlo, les muestro como me muestra los resultados en el TreeView a continuación.

(https://s17.postimg.org/j7piqsifj/image.png) (https://postimg.org/image/g0uz75xzf/)subir fotos online (https://postimage.org/index.php?lang=spanish)

Pues bien, como verán me cargan los datos, hasta allí todo OK, pero el detalle es de que me repite los Nro. De Ventas, aparte de eso tiene otro NODO que me muestra el detallado de dicha Venta, les muestro en la imagen siguiente:

(https://s9.postimg.org/7gj42plbz/image.png) (https://postimg.org/image/ewidoi917/)subir imagenes (https://postimage.org/index.php?lang=spanish)

Es así como me cargan los datos. Todo esta OK pero lo que trato de hacer es de que me agrupen los datos, ya se habrán dado cuenta de lo que trato de hacer, deberían de cargarme los datos de esta manera.

- GRACIELA MORENO CALVO

   --- Numero: 3 - Fecha: 01/03/2010

           --- Cant: 1 - Cartuchos HP 1100 Remanufacturado

           --- Cant: 10 - Teclado PS2 "Genius"

   --- Numero: 7 - Fecha: 15/03/2010

            :

            :

Quiero que me agrupe de esa manera, les dejo el código en la parte que cargo los datos, para ver en que parte tengo que agregar o midificar el codigo, gracias..

Código:
Option Explicit

Private Enum ObjectType
    otNone = 0
    otFactory = 1
    otGroup = 2
    otPerson = 3
    otFactory2 = 4
    otGroup2 = 5
    otPerson2 = 6
End Enum

Private Sub Form_Load()

    CARGAR_CONSULTA_NOMBRE

End Sub

Sub CARGAR_VENTA_SEGUN_NOMBRE(ByVal strQuery As String)
   
    '+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    '// Conectar la Base Datos con ADO
        Call ConectarBDD
    '+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
               
    Dim i As Long
   
   
    Dim FACTORY As Node
    Dim GROUP As Node
    Dim ARTICULO As Node
   
    Dim TIPO_ORDEN As String
   
    StrSQL = strQuery
    RST.Open StrSQL, CN, adOpenStatic, adLockOptimistic, adCmdText

    Do While Not RST.EOF
   
        With TreeView1.Nodes
                   
            .Clear
            Set FACTORY = .Add(, , , RST!NOMBRE_CLI, otFactory, 1)
       
            For i = 1 To RST.RecordCount
               
                'En esta parte es donde se repiten los N° DE ORDEN como se agrupa si hay dos o varios a la vez
                Set GROUP = .Add(FACTORY, tvwChild, , "Número: " & RST!IDVenta & " - " & "Fecha: " & RST!Fecha_Venta, otGroup, 2)
                Set ARTICULO = .Add(GROUP, tvwChild, , "Cant.: " & RST!Cantidad & " - " & RST!Nombre, 3)
               
                RST.MoveNext
                FACTORY.Expanded = True
           
            Next i
       
        End With
       
    Loop
   
    '+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    '// Cerrar la base de datos y liberar la memoria
        Call CerrarADO
    '+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
   
End Sub

'+----------------------------------------------------------------------------------------------
'// Consulta para mostrar los datos en el TreeView segun ID del cliente...
'+----------------------------------------------------------------------------------------------
Sub CARGAR_CONSULTA_NOMBRE()

    StrSQL = "SELECT VENTAS.IDVenta, VENTAS.Fecha_Venta, VENTAS_DETALLES.Cantidad, TBArticulos.Nombre, TBClientes.NOMBRE_CLI"
    StrSQL = StrSQL & " FROM (TBClientes INNER JOIN VENTAS ON TBClientes.NCLI = VENTAS.NCLI) INNER JOIN (TBArticulos INNER JOIN VENTAS_DETALLES ON TBArticulos.IDArticulo = VENTAS_DETALLES.IDArticulo) ON VENTAS.IDVenta = VENTAS_DETALLES.IDVenta"
    StrSQL = StrSQL & " WHERE ((TBClientes.NCLI=" & FrmGestionClientes.LvConsultClientes.SelectedItem & "))"
   
    Call CARGAR_VENTA_SEGUN_NOMBRE(StrSQL)
       
End Sub

MOD: Imagenes adaptadas a lo usado en el foro.


Título: Re: Agrupar datos de una BD en un TreeView VB 6.0
Publicado por: enterariel en 12 Octubre 2016, 22:47 pm
Te respondi aca

http://leandroascierto.com/foro/index.php?topic=3252.0 (http://leandroascierto.com/foro/index.php?topic=3252.0)