Hola a todos, tengo un problema con un treeview en vb .net, la cuestion es que tengo 5 tablas con los datos de una estrucutura y deseo llenar un treeview a partir de estas tablas,
como lo pongo a continuacion
'Tabla 1 Direccion General
ID DireccionGral
01 DIRECCION GENERAL DE SERVICIOS EDUCATIVOS
'tabla 2 Subdirecciones
ID DireccionGral Direccion
00 01 DIRECCION GENERAL
01 01 DIRECCION TECNICA
02 01 DIRECCION DE PLANEACION
03 01 DIRECCION REGIONAL DE CENTRO
04 01 DIRECCION REGIONAL DE JUAREZ
05 01 DIRECCION REGIONAL DE SAN LORENZO TEZONCO
07 01 DIRECCION REGIONAL DE SAN MIGUEL TEOTONGO
'tabla3 Departamentos
ID SubCoord Departamento
01 01 DEPARTAMENTO DE PLANEACION EDUCATIVA
02 01 DEPARTAMENTO DE PROGRAMACION EDUCATIVA
03 02 DEPARTAMENTO DE INFORMATICA
04 02 DEPARTAMENTO DE SERVICIOS COMPLEMENTARIOS
05 02 DEPARTAMENTO DE CONTROL ESCOLAR
06 05 DEPARTAMENTO DE GESTION ESCOLAR
07 05 DEPARTAMENTO DE DESARROLLO PROFESIONAL
08 05 DEPARTAMENTO DE DESARROLLO CURRICULAR
09 05 DEPARTAMENTO DE APOYO AL DESARROLLO CURRICULAR
10 07 DEPARTAMENTO DE PERSONAL
11 07 DEPARTAMENTO DE RECURSOS FINANCIEROS
12 07 DEPARTAMENTO DE RECURSOS MATERIALES Y SERVICIOS
13 07 DEPARTAMENTO DE APOYO JURIDICO
'Tabla 5 Oficinas
ID Departamento Oficina
01 10 OFICINA DE ARCHIVO
02 10 OFICINA DE ACLARACION AL PAGO
03 10 OFICINA DE CARRERA MAGISTERIAL
04 10 OFICINA DE KARDEX
05 10 OFICINA DE PAGADURIA
06 10 OFICINA DE RECLUTAMIENTO Y SELECCION DE PERSONAL
07 10 OFICINA DE REGISTRO Y CONTROL DE INCIDENCIAS
08 10 OFICINA DE SERVICIOS AL PERSONAL
09 10 OFICINA DE SIAPSEP
10 10 OFICINA DE TECHO FINANCIERO
11 10 OFICINA DE EMPLEO Y REMUNERACIONES
12 12 OFICINA DE ADQUISICIONES
13 12 OFICINA DE ALMACEN
14 12 OFICINA DE DISENO GRAFICO
15 12 OFICINA DE EDIFICIOS
16 12 OFICINA DE INVENTARIOS
17 12 OFICINA DE SERVICIOS GENERALES
el id es el enlace entre las tablas
y el proposito es que queden de la siguiente manera
Direccion gral
|-----Direccion
|----------Subdireccion
|---------------Departamento
|--------------------Oficina
sin embargo no lo he logrado
Has generado algo de codigo, alguna idea tienes de como hacerlo o no ¿?
de hecho si he generado un codigo y es este :
Dim nodo As TreeNode
Dim nodoDeps As TreeNode
Dim nodoDirs As TreeNode
Dim nodoSubs As TreeNode
Dim nodoOfs As TreeNode
Private Sub CargarNodos()
'conexion
Dim Cnn As New MySqlConnection("Database=SIARH;Data Source=localhost;User Id=root;Password=wolfman")
'cadenas sql
Dim SQLStrDirGral As String = "Select ID, DireccionGral, Sigs from TAuxCTDireccionGral"
Dim SQLStrDirecc As String = "Select ID, DireccionGral, Direccion, Sigs from TAuxCTDireccion"
Dim SQLStrSubdD As String = "Select ID, Direccion, SubDireccionCoordinacion, Sigs from TAuxCTSubDirCoord"
Dim SQLStrDepto As String = "Select ID, SubCoord, Departamento, Sigs from TAuxCTDeptos"
Dim SQLStrOfna As String = "Select ID, Departamento, Oficina, Sigs from TAuxCTOficinas"
'variables de busqueda
'Adaptadores
Dim daDirGral As New MySqlDataAdapter
Dim daDir As New MySqlDataAdapter
Dim daSubDir As New MySqlDataAdapter
Dim daDeptos As New MySqlDataAdapter
Dim daOfnas As New MySqlDataAdapter
'El dataset
Dim dsPlantilla As DataSet
'vista de datos
Dim dvDir As DataView
Dim dvSubdir As DataView
Dim dvDepto As DataView
Dim dvOfnal As DataView
dsPlantilla = New DataSet
SQLStrDirGral = "Select ID, DireccionGral, Sigs from TAuxCTDireccionGral"
daDirGral = New MySqlDataAdapter(SQLStrDirGral, Cnn)
daDirGral.Fill(dsPlantilla, "TAuxCTDireccionGral")
SQLStrDirecc = "Select ID, DireccionGral, Direccion, Sigs from TAuxCTDireccion"
daDir = New MySqlDataAdapter(SQLStrDirecc, Cnn)
daDir.Fill(dsPlantilla, "TAuxCTDireccion")
SQLStrSubdD = "Select ID, Direccion, SubDireccionCoordinacion, Sigs from TAuxCTSubDirCoord"
daSubDir = New MySqlDataAdapter(SQLStrSubdD, Cnn)
daSubDir.Fill(dsPlantilla, "TAuxCTSubDirCoord")
SQLStrDepto = "Select ID, SubCoord, Departamento, Sigs from TAuxCTDeptos"
daDeptos = New MySqlDataAdapter(SQLStrDepto, Cnn)
daDeptos.Fill(dsPlantilla, "TAuxCTDeptos")
SQLStrOfna = "Select ID, Departamento, Oficina, Sigs from TAuxCTOficinas"
daOfnas = New MySqlDataAdapter(SQLStrOfna, Cnn)
daOfnas.Fill(dsPlantilla, "TAuxCTOficinas")
'filas de datos se almacenan en esta categoria
Dim drDir As DataTable
Dim drSubDir As DataTable
Dim drDeptos As DataTable
Dim drOfnas As DataTable
Dim Regs As DataRow
'cargo las tablas que requiero
drDir = dsPlantilla.Tables("TAuxCTDireccion")
drSubDir = dsPlantilla.Tables("TAuxCTSubDirCoord")
drDeptos = dsPlantilla.Tables("TAuxCTDeptos")
drOfnas = dsPlantilla.Tables("TAuxCTOficinas")
dvDir = drDir.DefaultView
dvSubdir = drSubDir.DefaultView
dvDepto = drDeptos.DefaultView
dvOfnal = drOfnas.DefaultView
'primer nivel del Nodo principal
TreeView1.Nodes.Clear()
TreeView1.Nodes.Add("DIRECCION GENERAL")
' deshabilita la actualización en pantalla del control TreeView
TreeView1.BeginUpdate()
Dim i As Integer
Dim a As Integer
Dim aa As Integer
Dim b As Integer
Dim bb As Integer
For Each Regs In drDir.Rows
i = 0
' agrego el nodo en el segundo nivel
TreeView1.Nodes(i).Nodes.Add(Trim(Regs("Direccion")))
' realizo un filtro dentro de la vista
dvSubdir.RowFilter = "Direccion = " & Regs("id")
' ciclo para recorrer la vista previamente filtrada
aa = 0
For a = 0 To dvSubdir.Count - 1
' agrego el nodo en el tercer nivel
'aqui es en donde manda el error
TreeView1.Nodes(i).Nodes(aa).Nodes.Add(Trim(dvSubdir.Item(a).Row("SubDireccionCoordinacion")))
Specified argument was out of the range of valid values.
Parameter name: index
' realizo un filtro dentro de la vista
dvDepto.RowFilter = "SubCoord = " & Regs("id")
bb = 0
For b = 0 To dvDepto.Count - 1
TreeView1.Nodes(i).Nodes(a).Nodes(bb).Nodes.Add(Trim(dvDepto.Item(b).Row("Departamento")))
Next
Next
i = i + 1
Next
' habilita la actualización en pantalla del control TreeView
TreeView1.Nodes(i).ExpandAll()
' habilita la actualización en pantalla del control TreeView
TreeView1.EndUpdate()
End Sub
Hola nuevamente, bueno, es lo unico que queria saber, empezemos. Antes que nada decirte que particularmente me gusta usar la menor cantidad de variables posible. y trabajar por bloques. Si lo que deseas hacer es mostrar una subcategoria de una categoria solo es usar bucles (en este caso usare for), veamos un ejemplo:
Imports system.data.sqlclient
Public class formulario
Dim con as new sqlconnection("integrated security=sspi;data source=(local);initial catalog=DB")
Dim da as sqldataadapter
Dim dtb,d1,d2,d3,d4,d5 as Datatable
function Direccion() as datatable
da = new sqldataadapter("select id_direccion,direccion from direccion",con)
dtb = new datatable
da.fill(dtb)
return dtb
end function
function subdireccion(byval id as string) as datatable
da = new sqldataadapter("select id_subdireccion,direccion from subdireccion where id_direccion='" & id & "'",con)
dtb = new datatable
da.fill(dtb)
return dtb
end function
function departamento(byval id as string) as datatable
da = new sqldataadapter("select id_departamento,departamento from departamento where id_subdireccion='" & id & "'",con)
dtb = new datatable
da.fill(dtb)
return dtb
end function
function oficinas(byval id as string) as datatable
da = new sqldataadapter("select id_oficina,oficina from oficina where id_departamento='" & id & "'",con)
dtb = new datatable
da.fill(dtb)
return dtb
end function
'Esto es lo que puedes modificar, puedes reducirlo.Citarsub llenatreeview()
dim a,b,c,d as integer
dim id1,id2,id3,id4 as string 'variable para los codigos
dim ca1,ca2,ca3,ca4 as string 'variable para los textos
for a = 0 to direccion.rows.count-1
id1 = direccion.rows(a)("id_direccion").tostring
ca1 = direccion.rows(a)("direccion").tostring
treeview1.nodes.add (ca1)
for b = 0 to subdireccion(id1).rows.count-1
id2 = subdireccion.rows(b)("id_subdireccion").tostring
ca2 = subdireccion.rows(b)("subdireccion").tostring
treeview1.nodes(treeview1.nodes.count-1).nodes.add (ca2)
for c = 0 to departamento.rows.count-1
id3 = departamento.rows(c)("id_departamento").tostring
ca3 = departamento.rows(c)("departamento").tostring
treeview1.nodes(treeview1.nodes.count-1).nodes(treeview1.nodes(treeview1.nodes.count-1).nodes.count-1).nodes.add (ca3)
for d = 0 to oficinas.rows.count-1
id4 = departamento.rows(c)("id_departamento").tostring
ca4 = departamento.rows(c)("departamento").tostring
end for
end for
end for
end for
end sub
end class
Tambien tener en cuenta que puedes usar recursividad, puedes mirar este post, y reducir el bloque de codigo. Saludos. Espero sirva.
http://foro.elhacker.net/index.php/topic,186323.0.html
Hola, chicos! Estoy buscando un software de gestión de la escuela de mi consejo escolar. Me puse en contacto en línea, pero algunos profesionales que estaban pidiendo mucho dinero por sólo un poco de trabajo. Si alguien sabe donde puedo conseguir el software de gestión de las escuelas de cualquier tipo. Por favor, me pm.
Gestion escolar (http://www.softaula.net/)