salut a tous
je veux svp comment manipuler un controle treeview avec column
merci
salut a tous
je veux svp comment manipuler un controle treeview avec column
merci
Une des façon de faire que je pourrais te conseiller serais de créer une colonne image dans ton gridview, et d'y mettre une image comme un noeud de treeview :
Tu peux regarder ce code que j'utilise dans mon cas pour définir les noeuds la où j'ai mes titres. Ensuite j'y insère un "+" dans une colonne "indice" ainsi que une l'image "+", si je veux que au chargement le treeview soit réduit, et inverse si je veux que au chargement le treeview soit développé. Pour ce qui n'est pas "titre" je met donc une image "blanche" mais rien n'empêche d efaire des sous-noeuds, où de faire des traits comme dans l'image mis en lien.
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 Public Sub treeview(ByVal Grid As DataGridView, ByVal table As DataTable, ByVal signe As String, ByVal im As Image) 'On récupère le nombre de ligne en focntion de la grille maxlignes = table.Rows.Count For i = 0 To maxlignes - 1 'gestion de la ligne total de la grille "avancement" (la dernière ligne) If Grid Is Datagrid1 And i = maxlignes - 1 Then Grid.Rows(i).Cells(0).Value = My.Resources.vide Grid.Rows(i).Cells(1).Value = "Tot" Grid.Item(2, i).Style.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Italic) Grid.Item(3, i).Style.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Italic) Grid.Item(3, i).Style.ForeColor = Red Grid.Rows(i).Cells(5).Value = System.DBNull.Value Grid.Rows(i).Cells(6).Value = System.DBNull.Value Grid.Rows(i).Cells(7).Value = System.DBNull.Value 'gestion du cas où l'on rencontre un titre (colonne "unité" vide) ElseIf Grid.Rows(i).Cells(4).Value = "" Then Grid.Rows(i).Cells(0).Value = im Grid.Rows(i).Cells(1).Value = signe 'Au passage on met les cellules des titres et des numéro de ligne en gras Grid.Item(2, i).Style.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold) Grid.Item(3, i).Style.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold) Grid.Rows(i).Cells(5).Value = System.DBNull.Value Grid.Rows(i).Cells(6).Value = System.DBNull.Value Grid.Rows(i).Cells(7).Value = System.DBNull.Value Else 'si on a un "+", on a donc une grille "réduite", si l'on a un "-", on a une grille développée If signe = "+" Then Grid.Rows(i).Cells(0).Value = My.Resources.vide Grid.Rows(i).Visible = False Else Grid.Rows(i).Cells(0).Value = My.Resources.vide End If End If Next i End Sub
Ensuite je gère l'évènement de la sorte :
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 Public Sub DataGrid1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Datagrid1.CellClick ligne = Datagrid1.CurrentCell.RowIndex colonne = Datagrid1.CurrentCell.ColumnIndex maxlignes = TableActivity.Rows.Count 'Ce qui se produit quand on clique sur le "+" ou le "-" du treeview 'Image qui fonctionne comme un bouton à double commande 'cas du "+" If colonne = 0 And Datagrid1.Rows(ligne).Cells(1).Value = "+" Then Datagrid1.Rows(ligne).Cells(1).Value = "-" Datagrid1.Rows(ligne).Cells(0).Value = My.Resources.moinss For i = ligne + 1 To maxlignes - 1 If Datagrid1.Rows(i).Cells(1).Value = "" Then Datagrid1.Rows(i).Visible = True End If If Datagrid1.Rows(i).Cells(1).Value = "+" Or Datagrid1.Rows(i).Cells(1).Value = "-" Then Exit For End If Next i 'cas du "-" ElseIf colonne = 0 And Datagrid1.Rows(ligne).Cells(1).Value = "-" Then Datagrid1.Rows(ligne).Cells(1).Value = "+" Datagrid1.Rows(ligne).Cells(0).Value = My.Resources.pluss For i = ligne + 1 To maxlignes - 1 If Datagrid1.Rows(i).Cells(1).Value = "" Then Datagrid1.Rows(i).Visible = False End If If Datagrid1.Rows(i).Cells(1).Value = "-" Or Datagrid1.Rows(i).Cells(1).Value = "+" Then Exit For End If Next i End If End Sub
PS : Une autre façon serait de surcharger le "contrôle" gridview pour y insérer directement le contrôle "treeview", au même titre qu'il existe des colonnes "combobox", "textbox", "imagebox", "checkbox, etc ...
Partager