Bonjour,
J'ai un TreeView que je remplie avec une Table que j'ai elle même remplie avec une procédure stockée.
J'ai réussi mais le problème c'est que mes noeuds ne sont pas rangés par ordre alphabétique.
Je me suis donc dis que j'allais faire un ORDER BY dans ma procédure mais maintenant mon système de remplissage ne fonctionne plus.
Voici ma table OBJET (qui correspond pour ceux qui me suivent à tous mes form et control):
Voici comment je la remplie :Objet_Id | Objet_Name | Objet_Type | Objet_Id_Père
Donc au début j'ajoute une ligne consultation application avec un père à 0.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 private void parcourControl(Control c, int IdPere) { //AJOUT DANS LA BASE if (c.GetType().ToString() != "System.Windows.Forms.VScrollBar" && c.GetType().ToString() != "System.Windows.Forms.HScrollBar") { string sql = "AjoutObjet '" + c.Name + "','" + c.GetType().ToString() + "','" + IdPere.ToString() + "' "; SqlConnection ConsultConnection = new SqlConnection(oSurveillant.strConnexionSecurite); SqlCommand Command = new SqlCommand(sql, ConsultConnection); Command.Connection.Open(); int IdFils = (int)Command.ExecuteScalar(); Command.Connection.Close(); if (c.Controls.Count != 0) { foreach (Control c1 in c.Controls) { parcourControl(c1, IdFils); } } } } private void Bt_Upload_Click(object sender, EventArgs e) { string sql = "ViderObjets "; SqlConnection ConsultConnection = new SqlConnection(oSurveillant.strConnexionSecurite); SqlCommand Command = new SqlCommand(sql, ConsultConnection); Command.Connection.Open(); Command.ExecuteNonQuery(); Command.Connection.Close(); string sql2 = "AjoutObjet 'Consultation' ,'Application','0' "; SqlConnection ConsultConnection2 = new SqlConnection(oSurveillant.strConnexionSecurite); SqlCommand Command2 = new SqlCommand(sql2, ConsultConnection2); Command2.Connection.Open(); Id_Application = (int)Command2.ExecuteScalar(); Command2.Connection.Close(); Assembly asm = Assembly.GetExecutingAssembly(); // Parcours de tous les types de l'assembly foreach (Type t in asm.GetTypes()) { // Il s'agit d'une form if (t.BaseType == typeof(Form)) { string sql3 = "AjoutObjet '" + t.Name.ToString() + "','" + t.BaseType.ToString() + "','" + Id_Application.ToString() + "'"; SqlConnection ConsultConnection3 = new SqlConnection(oSurveillant.strConnexionSecurite); SqlCommand Command3 = new SqlCommand(sql3, ConsultConnection3); Command3.Connection.Open(); IdFormEnCours = (int)Command3.ExecuteScalar(); Command3.Connection.Close(); if (t.Name.ToString() == "F_ConsultRef") { Form f = (Form)Activator.CreateInstance(t, oSurveillant, false); foreach (Control c in f.Controls) { parcourControl(c, IdFormEnCours); } } else { Form f = (Form)Activator.CreateInstance(t, oSurveillant); foreach (Control c in f.Controls) { parcourControl(c, IdFormEnCours); } } } } }
Je veux que cette ligne soit mon premier noeud.
Et ensuite j'ajoute le premier form que je trouve et puis tous ses control, après je passe au form d'après et ses control, ainsi de suite.
Voici comment je remplie mon arbre:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 private void TreeView_Load() { TreeViewObjets.Nodes.Clear(); ChargerObjet(); // Fonction qui remplie MaTableObjet avec ma procédure stockée TreeNode n = new TreeNode(MaTableObjet.Rows[0][1].ToString() + " - " + MaTableObjet.Rows[0][2].ToString()); this.TreeViewObjets.Nodes.Add(n); TreeNode nn = new TreeNode(MaTableObjet.Rows[1][1].ToString() + " - " + MaTableObjet.Rows[1][2].ToString().Remove(0, 21)); n.Nodes.Add(nn); string IdPere = MaTableObjet.Rows[1][0].ToString(); string IdGrandPere = MaTableObjet.Rows[0][0].ToString(); BoucleArbre(IdGrandPere, IdPere, n, nn, 2); BoucleProperty(); // Fonction qui ajoute les property qui sont ajoutées à la main } public void BoucleArbre(string IdGrandPere, string IdPere, TreeNode NGrandPere, TreeNode NPere, int a) { TreeNode n1 = null; int i = a; if (i < MaTableObjet.Rows.Count) { n1 = new TreeNode(MaTableObjet.Rows[i][1].ToString() + " - " + MaTableObjet.Rows[i][2].ToString().Remove(0, 21)); // ERREUR :L'index et le compte doivent faire référence à un emplacement situé dans la chaîne. //Nom du paramètre : count string IdPereEnCours = MaTableObjet.Rows[i][3].ToString(); if (IdPereEnCours == IdGrandPere) { NGrandPere.Nodes.Add(n1); NPere = n1; a++; } else { NPere.Nodes.Add(n1); a++; } BoucleArbre(IdGrandPere, IdPere, NGrandPere, NPere, a); } }
Comme pour remplir mon arbre je m'appuyai sur le fait que dans MaTableObjet j'avais :
Appli
Form
Control
Control
Form
Control
Maintenant pour mon petit raisonnement qui m'avait demandé un travail cérébral intance ne fonctionne plus.
Peut_être y a t il un moyen de trier l'arbre après l'avoir remplie, ou de trier MaTableObjet quand je la remplie ou de trier la table dans la base en la remplissant?
Merci d'avance, surtout si vous avez eu le courage de lire tout ce qui précède.
Partager