Treeview et Base de donnée : Initilisation

Résolu
cs_tiolebucheron Messages postés 20 Date d'inscription jeudi 20 mars 2003 Statut Membre Dernière intervention 2 novembre 2010 - 23 mars 2005 à 16:22
cs_tiolebucheron Messages postés 20 Date d'inscription jeudi 20 mars 2003 Statut Membre Dernière intervention 2 novembre 2010 - 28 mars 2005 à 18:31
Bonjour


Je cherche à mettre en place un treeview a partir d'une base de données. Voici la structure de la base et des exemple de jeu de données



<HR>



ID-HTML EXPANDED ICON
1 A - DOCUMENTS D'ORIENTATION ET DE GESTION 1 help_book.gif
2 B - ECONOMIE FORESTIERE ET FILIERE BOIS 1 help_book.gif
3 C - COMMUNICATION , PROMOTION DE LA FORET 1 help_book.gif
4 D - DEVELOPPEMENT FORESTIER 1 help_book.gif
5 E - PROTECTION DES FORETS ENVIRONNEMENT 1 help_book.gif
6 F - AMENAGEMENT DU TERRITOIRE 1 help_book.gif
7 G - FONCTIONNEMENT DU CRPF 1 help_book.gif
8 H - CONGES 1 help_book.gif
9 1 a1 - ORF 0 folder.gif
10 1 a2 - SRGS 0 folder.gif
11 1 a3 - Code de bonnes pratiques 0 folder.gif
12 1 a4 - Plans simples de gestion 1 folder.gif
13 12 a41 - Plan types 0 page.gif
14 12 a42 43 - Administration des PSG et appels 0 page.gif
15 12 a44 - Prospection gestion durable Visite avant PSG 0 page.gif
16 12 a45 - Instruction des PSG, modificatif 0 page.gif
17 12 a46 - Suivi des PSG 0 page.gif
18 12 a47 - Coupes extraordinaires 0 page.gif



<HR>

Je suis arrivé à progammer ceci du coté ASP
<%@ Page Language= "vb" AutoEventWireup="false" Codebehind="Planclass.aspx.vb" Inherits="Planclass.Planclass"%> <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Planclass.aspx.vb" Inherits="Planclass.Planclass"%> <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Planclass.aspx.vb" Inherits="Planclass.Planclass"%>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML> <HEAD>
<title>Planclass</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<form id="Form1" method="post" runat="server">
</form>
</HTML><%@ Register TagPrefix ="iewc" Namespace= "Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<META content="Microsoft Visual Studio .NET 7.1" name=GENERATOR>
<META content="Visual Basic .NET 7.1" name=CODE_LANGUAGE>
<META content=JavaScript name=vs_defaultClientScript>
<META content=http://schemas.microsoft.com/intellisense/ie5 name=vs_targetSchema>



<FORM id=Form1 method=post runat="server"><?xml:namespace prefix = iewc /> du coté VB
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim masterNode As New TreeNode
Dim sParentID As String
Dim CurRows() As DataRow, CurRow As DataRow
objBddPlanclass.GetBddPlanclass()
CurRows = objBddPlanclass.BddPlanclassList.Select
For Each CurRow In CurRows
If CurRow("PARENT") Is DBNull.Value Then
sParentID = "root"
Else
sParentID = CurRow("PARENT").ToString ' ID should start with character or maybe not?
End If
AddNode(sParentID, "id" & CurRow("ID").ToString, CurRow("HTML").ToString, CurRow("EXPANDED").ToString, CurRow("ICON").ToString)
Next
End Sub</FORM>



<FORM id=Form1 method=post runat="server">


Private Sub AddNode(ByVal id_parent As String, ByVal id_child As String, ByVal html As String, ByVal expanded As String, ByVal icon As String)
Dim childNode As New TreeNode
childNode.Nodes.Clear()
childNode.Text = html & " " & id_parent & " " & id_child & " " & childNode.GetNodeIndex
childNode.ID = id_child
If id_parent = "root" Then
TreeView1.Nodes.Add(childNode)
Else
TreeView1.Nodes(0).Nodes.Add(childNode)
End If
childNode = Nothing
End Sub





Mon problème est que je ne vois pas comment intégrer les noeud fils au bonne endroit.
Merci de votre aide.

A bientot tiolebucheron</FORM>

2 réponses

cs_tiolebucheron Messages postés 20 Date d'inscription jeudi 20 mars 2003 Statut Membre Dernière intervention 2 novembre 2010
28 mars 2005 à 18:31
3
cs_tiolebucheron Messages postés 20 Date d'inscription jeudi 20 mars 2003 Statut Membre Dernière intervention 2 novembre 2010
26 mars 2005 à 07:45
J'ai avancé dans la réalisation mais il me manque pas grand chose.
Voici le code

Private Sub AddNode(ByRef oTree As TreeNode, ByVal id_parent As String, ByVal id_child As String, ByVal html As String, ByVal expanded As String, ByVal icon As String)
Dim childNode As New TreeNode
Dim int As Integer
childNode.Nodes.Clear()
childNode.Text = html
childNode.ID = id_child
childNode.Expanded = expanded


If id_parent = "root" Then
oTree.Nodes.Add(childNode)
Else
'RetournerNoeud(oTree, id_parent).Nodes.Add(childNode)
End If
childNode = Nothing
End Sub


Public Function RetournerNoeud(ByVal oTree As TreeNode, ByVal wKey As String) As TreeNode
Dim i As Integer
Dim str As String


RetournerNoeud = Nothing
For i = 0 To oTree.Nodes.Count
If oTree.Nodes(i).ID = wKey Then
RetournerNoeud = oTree.Nodes(i)
Exit Function
Else
If oTree.Nodes(i).Expanded = True Then
RetournerNoeud(oTree.Nodes(i), wKey)
Exit For
End If
End If
Next
End Function

J'ai un soicis dans la partie en rouge cela ne fonctionne pas correctement.
Pour être plus clair voici ma démarche
PageLoad
Ajout du noued racine au Treeview
Parcours du tableau contenant les noeud
Ajout le noeud au noeud racine


AddNode
initialisation du noeud fils
Ajout le noeud au noeud Parent


recherche noeud
Parcour du noeud racine
si l'identifiant est égale à l'identifiant du noeud rechercher
on retourne le noeud correspond
sinon
si le noeud peut être parent a son tour
on recherche le noeud dans le sous arbre

Aidez moi SVP je galère pas mal Meci d'avance
0
Rejoignez-nous