| |||
Re: Cargar treeview desde una consulta Si es para un treeview de un winform quedaria mas o menos asi: Esto es para una sola tabla..... Donde la estructura seria asi
Código:
Id Nombre Id_padre 1 Uno 0 2 dos 0 3 tres 0 4 cuatro 1 5 cinco 1 6 seis 2 7 siete 3
Código:
Espero y te sirva....'Hago esta declaracion fuera del load Dim aIndex(20) As Integer Dim nLevel As Integer ---------------------------- Dim oNode As TreeNode Tree.BeginUpdate() Tree.Nodes.Clear() load Dim sSQL As String = "select mis_campos from my_tabla where id_padre=0" 'Hago mi conexion 'suponiendo que ya tengo mis datos en un datatable Dim i As Integer Dim dr As DataRow For Each dr In dt.Rows aIndex(nLevel) = i oNode = New TreeNode oNode.Text = dr("Nombre") oNode.Tag &= dr("Id") Tree.Nodes.Add(oNode) 'si quiero que tenga mas de un nivel mando a llamar la siguiente funcion Find_Items(dr("Id")) i += 1 Next End If Tree.EndUpdate() end load Private Sub Find_Items(ByVal nId As Integer) nLevel += 1 Dim sSQL As String = "select * from tabla where id_padre = " & nId Dim dt As DataTable 'Hacemos la conexion Dim oNode As TreeNode Dim i As Integer Dim dr As DataRow For Each dr In dt.Rows aIndex(nLevel) = i oNode = New TreeNode oNode.Text = dr("Nombre") oNode.Tag &= dr("Id") oNode.Expand() Select Case nLevel Case 1 Tree.Nodes(aIndex(0)).Nodes.Add(oNode) Case 2 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes.Add(oNode) Case 3 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes.Add(oNode) Case 4 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes.Add(oNode) Case 5 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes.Add(oNode) Case 6 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes.Add(oNode) Case 7 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes.Add(oNode) Case 8 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes.Add(oNode) Case 9 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes.Add(oNode) Case 10 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes.Add(oNode) Case 11 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes.Add(oNode) Case 12 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes.Add(oNode) Case 13 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes.Add(oNode) Case 14 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes(aIndex(13)).Nodes.Add(oNode) Case 15 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes(aIndex(13)).Nodes(aIndex(14)).Nodes.Add(oNode) Case 16 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes(aIndex(13)).Nodes(aIndex(14)).Nodes(aIndex(15)).Nodes.Add(oNode) Case 17 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes(aIndex(13)).Nodes(aIndex(14)).Nodes(aIndex(15)).Nodes(aIndex(16)).Nodes.Add(oNode) Case 18 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes(aIndex(13)).Nodes(aIndex(14)).Nodes(aIndex(15)).Nodes(aIndex(16)).Nodes(aIndex(17)).Nodes.Add(oNode) Case 19 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes(aIndex(13)).Nodes(aIndex(14)).Nodes(aIndex(15)).Nodes(aIndex(16)).Nodes(aIndex(17)).Nodes(aIndex(18)).Nodes.Add(oNode) Case 20 Tree.Nodes(aIndex(0)).Nodes(aIndex(1)).Nodes(aIndex(2)).Nodes(aIndex(3)).Nodes(aIndex(4)).Nodes(aIndex(5)).Nodes(aIndex(6)).Nodes(aIndex(7)).Nodes(aIndex(8)).Nodes(aIndex(9)).Nodes(aIndex(10)).Nodes(aIndex(11)).Nodes(aIndex(12)).Nodes(aIndex(13)).Nodes(aIndex(14)).Nodes(aIndex(15)).Nodes(aIndex(16)).Nodes(aIndex(17)).Nodes(aIndex(18)).Nodes(aIndex(19)).Nodes.Add(oNode) End Select 'Hago la recursividad para llenar mis datos de la tabla en n niveles llamando la funcion Find_Items(dr("Id")) i += 1 Next End If nLevel -= 1 End Sub Bitss---Miguel--in--........ |
| |||
Respuesta: Cargar treeview desde una consulta que tal mi buen amigo, pues lo he tratado de implementar en php plataforma web tu sabes!, y usando una mase de datos de mysql, de echo la tabla es la misma estructura aunque tiene mas campos pero los importantes son los tres que muestras, pero de verdad que no se como hacerle en php pues no me sale nada ni por donde hacerle pues me arroja puros errores, si tuvieras alguna opcion que me sirva te agradeceria mucho |