J'ai essayé de changer l'indice avec celui du dgv ou celui de la table access rien a faire. De meme quand je retire le tri dans le combobox ça ne change rien
J'ai essayé de changer l'indice avec celui du dgv ou celui de la table access rien a faire. De meme quand je retire le tri dans le combobox ça ne change rien
Veux-tu bien modifier ton code de remplissage du Combo comme ceci (au moins le Combo1, mais tu peux faire la même chose pour tous) :
et puis tu pourras réessayer mon code avec le nom de colonne (PN) d'abord et en revenir à l'indice 12 ensuite, si ça ne va toujours pas =
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 Dim Matable As DataTable Matable = DtSet.Tables("tblToolRequisition") DataGridView1.DataSource = Matable ComboBox1.DataSource = Matable ComboBox1.DisplayMember = "PN" ' Dim dr As OleDbDataReader = cmd.ExecuteReader ' While dr.Read ' ComboBox1.Items.Add(dr(12).ToString) ' ComboBox2.Items.Add(dr(11).ToString) ' ComboBox3.Items.Add(dr(4).ToString) ' ComboBox4.Items.Add(dr(16).ToString) ' End While ' ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() IndexColonne = DataGridView1.Columns("PN").Index For IndexLigne = 0 To DataGridView1.Rows.Count - 1 If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox1.Text Then DataGridView1Rows(IndexLigne).Selected = True End If Next End Sub
Super ca marche maintenant
Je voudrais pas abuser mais j'ai des doublons dans la combobox, j'aimerais savoir si c'est possible de d'avoir la combobox sans doublons et dans l'ordre alphabetique ?
pour l'ordre j'ai essaye avec Sorted = True mais apres qund je choisis le client numero 3 par exemple, il me montre le PN numero 3 dans la liste
pour les doublons j'ai vu qu'on peut utilisermais comme j'ai utiliser
Code : Sélectionner tout - Visualiser dans une fenêtre à part "Select Distinct nom From Table Order By nom"
je vois pas comment faire
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2ComboBox1.DataSource = Matable ComboBox1.DisplayMember = "PN"
si t'as une piste je t'en remercie
Tu as trouvé le bon code ...
Voici comment faire.
Juste avant la requête qui livre les données pour le DataGridView, avant de créer la DataTable pour le DataSet nommé DtSet, tu dois faire une première requête Dim cmd As New OleDbCommand("select distinct PN from tblToolRequisition Order by PN asc", cn).
Cette requête doit te donner un premier DataTable pour le DtSet.
Une fois ce DataTable dans le DtSet, il faut changer son nom : Dts.Tables(0).TableName = "tblPN" par exemple.
Seulement ensuite tu fais ce qu'il faut pour avoir la table tblToolRequisition.
Note que tu peux ici réutiliser le cmd existant (sans New) :
cmd = OleDbCommand("select * from tblToolRequisition", cn).
Après tout cela, tu peux lier ton DataGridView comme c'est actuellement fait et enfin, lier le Combo1 :
Note encore que tu n'es pas obligé de passer par MaTable pour lier le DataGridView, tu peux faire directement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 ComboBox1.DataSource = DtSet.Tables("tblPN") ComboBox1.DisplayMember = "PN"
DataGridView1.DataSource = DtSet.Tables("tblToolRequisition")
Genial merci j'essayerais demain
Alors j'ai essayé de faire comme tu as dis et ça ne marche pas, j'ai crée de nouvelles commandes mais il ne m'affiche plus rien
en fait je vois pas comment tu peux reutiliser chaque commandes telles que cmd, DtSet... surtout que j'ai 4 combobox
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 Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source = Database2.accdb") cn.Open() Dim cmd As New OleDbCommand("select * from tblToolRequisition", cn) Dim cmd1 As New OleDbCommand("select distinct PN from tblToolRequisition Order by PN asc", cn) Dim AdapTContact1 As OleDb.OleDbDataAdapter Dim DtSet1 As New DataSet() AdapTContact1 = New OleDbDataAdapter(cmd1) AdapTContact1.Fill(DtSet1, "tblToolRequisition") DtSet1.Tables(0).TableName = "tblPN" Dim AdapTContact As OleDb.OleDbDataAdapter Dim DtSet As New DataSet() AdapTContact = New OleDbDataAdapter(cmd) AdapTContact.Fill(DtSet, "tblToolRequisition") DataGridView1.DataSource = DtSet.Tables("tblToolRequisition") ComboBox1.DataSource = DtSet.Tables("tblPN") ComboBox1.DisplayMember = "PN"
Veux-tu bien mettre tout ton code en commentaire et exécuter le mien à la place :
J'ai un peu difficile à tester, le code que j'utilise est réglé pour SqlExpress, mais surtout il est tout-à-fait structuré différemment du tien ...
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 '****************************************************************************** Dim ChaineConnexion As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source = Database2.accdb" ' cn.Open() ''' Ne pas faire l'ouverture effective pour le DataAdapter, il s'en charge ... ' Dim cmd As New OleDbCommand("select distinct PN from tblToolRequisition Order by PN asc", cn) Dim DtSet As New DataSet() Dim UneTable As New DataTable Dim cn As New OleDbDataAdapter("select distinct PN from tblToolRequisition Order by PN asc", ChaineConnexion) ' cn.FillSchema(UneTable, SchemaType.Source) '"'Pas toujours nécessaire cn.Fill(UneTable) DtSet.Tables.Add(UneTable) DtSet.Tables(0).TableName = "tblPN" Dim AdapTContact As OleDb.OleDbDataAdapter UneTable = New DataTable cn = New OleDbDataAdapter("select * from tblToolRequisition", ChaineConnexion) ' cn.FillSchema(UneTable, SchemaType.Source) '"'Pas toujours nécessaire cn.Fill(UneTable) DtSet.Tables.Add(UneTable) ' DtSet.Tables(1).TableName = "tblToolRequisition" DataGridView1.DataSource = DtSet.Tables("tblToolRequisition") ComboBox1.DataSource = DtSet.Tables("tblPN") ComboBox1.DisplayMember = "PN" '******************************************************************************
super ca marche mais je vois pas comment je peux rajouter les 3 autres combobox pcq cn correspond a PN
Je suppose que tous tes Combox ne sont chargés avec de PN ...
Je suppose que le ComboBox1 présente les PN, ComboBox2 présente les ..., ...
Tu peux alors refaire ce que j'ai fait pour chaque Combo :
Une requête avec l'ajout d'une UneTable dans le DtSet et le renommer de sorte à la retrouver
Pour le renommer, la dernière table ajoutée étant à l'indice Count-1, tu devrais pour écrire DtSet.Tables(DtSet.Tables.Count -1).TableName = ...
Lier le Combo à la table que tu viens de faire et au champ de donnée concerné :
ComboBox.DataSource = DtSet.Tables("Le nom de la table")
ComboBox.DisplayMembre = "Le nom du champ")
Mais l'organisation de ton code (si je peux me permettre n'est pas optimale ...
Lorsqu'on écrit des fonctions distinctes pour la collecte des données dans la DB et pour la liaison de ces données aux composants visuels, le programme devient plus lisible et semble alors plus simple ...
j'ai a peu pres compris suaf pour cn car au debut il correspond a PN et apres il correspond a tblToolRequisition donc j'ai essaye de rajouter la combobox 2 mais il 'affiche qu'1 seule colonne et ne remplis que le combobox1
C'est ce que j'ai essaye meme si c'est faux
Desole de te deranger mais j'essaie de comprendre
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 Dim ChaineConnexion As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source = Database2.accdb" Dim DtSet As New DataSet() Dim UneTable1 As New DataTable Dim UneTable2 As New DataTable Dim UneTable3 As New DataTable Dim UneTable4 As New DataTable Dim cn1 As New OleDbDataAdapter("select distinct PN from tblToolRequisition Order by PN asc", ChaineConnexion) Dim cn2 As New OleDbDataAdapter("select distinct CustomerName from tblToolRequisition Order by CustomerName asc", ChaineConnexion) Dim cn3 As New OleDbDataAdapter("select distinct ToolDRG from tblToolRequisition Order by ToolDRG asc", ChaineConnexion) Dim cn4 As New OleDbDataAdapter("select distinct RequistionNum from tblToolRequisition Order by RequistionNum asc", ChaineConnexion) cn1.Fill(UneTable1) cn2.Fill(UneTable2) cn3.Fill(UneTable3) cn4.Fill(UneTable4) DtSet.Tables.Add(UneTable1) DtSet.Tables.Add(UneTable2) DtSet.Tables.Add(UneTable3) DtSet.Tables.Add(UneTable4) DtSet.Tables(0).TableName = "tblPN" DtSet.Tables(DtSet.Tables.Count - 1).TableName = "tblCustomer" Dim AdapTContact1 As OleDb.OleDbDataAdapter UneTable1 = New DataTable UneTable2 = New DataTable UneTable3 = New DataTable UneTable4 = New DataTable cn1 = New OleDbDataAdapter("select * from tblToolRequisition", ChaineConnexion) cn1.Fill(UneTable1) DtSet.Tables.Add(UneTable1) DtSet.Tables(1).TableName = "tblToolRequisition" DataGridView1.DataSource = DtSet.Tables("tblToolRequisition") ComboBox1.DataSource = DtSet.Tables("tblPN") ComboBox1.DisplayMember = "PN" ComboBox2.DataSource = DtSet.Tables("tblCustomer") ComboBox2.DisplayMember = "CustomerName"
Tu ne me déranges pas, je ne suis sur ce forum que pour aider, et seulement quand j'en ai le temps ...
Quelques problèmes dans ton code (je mets en commentaires et fais quelques modif ...) :
Et après ça, tu peux récrire la procédure événementiel pour chaque Combo et produire à chaque fois la sélection des lignes du DataGrid.
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 Dim ChaineConnexion As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source = Database2.accdb" Dim DtSet As New DataSet() Dim UneTable1 As New DataTable Dim UneTable2 As New DataTable Dim UneTable3 As New DataTable Dim UneTable4 As New DataTable Dim cn1 As New OleDbDataAdapter("select distinct PN from tblToolRequisition Order by PN asc", ChaineConnexion) ' tblPN Dim cn2 As New OleDbDataAdapter("select distinct CustomerName from tblToolRequisition Order by CustomerName asc", ChaineConnexion) ' tblCustomer Dim cn3 As New OleDbDataAdapter("select distinct ToolDRG from tblToolRequisition Order by ToolDRG asc", ChaineConnexion) ' tblTool Dim cn4 As New OleDbDataAdapter(""select * from tblToolRequisition"", ChaineConnexion) '' Dim cn4 As New OleDbDataAdapter("select distinct RequistionNum from tblToolRequisition Order by RequistionNum asc", ChaineConnexion) ' ça n'a pas de sens de chercher sur l'ID, il est unique et est présenté par ordre dans le DataGrid cn1.Fill(UneTable1) cn2.Fill(UneTable2) cn3.Fill(UneTable3) cn4.Fill(UneTable4) DtSet.Tables.Add(UneTable1) DtSet.Tables.Add(UneTable2) DtSet.Tables.Add(UneTable3) DtSet.Tables.Add(UneTable4) DtSet.Tables(0).TableName = "tblPN" DtSet.Tables(1).TableName = "tblCustome" DtSet.Tables(2).TableName = "tblTool" DtSet.Tables(3).TableName = "tblToolRequisition" ' DtSet.Tables(DtSet.Tables.Count - 1).TableName = "tblCustomer" ' Dim AdapTContact1 As OleDb.OleDbDataAdapter ' UneTable1 = New DataTable ' UneTable2 = New DataTable ' UneTable3 = New DataTable ' UneTable4 = New DataTable ' cn1 = New OleDbDataAdapter("select * from tblToolRequisition", ChaineConnexion) ' cn1.Fill(UneTable1) ' DtSet.Tables.Add(UneTable1) ' DtSet.Tables(1).TableName = "tblToolRequisition" DataGridView1.DataSource = DtSet.Tables("tblToolRequisition") ComboBox1.DataSource = DtSet.Tables("tblPN") ComboBox1.DisplayMember = "PN" ComboBox2.DataSource = DtSet.Tables("tblCustomer") ComboBox2.DisplayMember = "CustomerName" ComboBox3.DataSource = DtSet.Tables("tblTool") ComboBox3.DisplayMember = "ToolDRG"
Quand c'est OK, il faudra chercher à n'écrire qu'une seule procédure pour tous les Combo de sélection ...
Alors maintenant j'ai toutes mes combobox triees mais mon dgv n'affiche que la colonne "Customer"
Je remets tout mon code au cas ou mais je vois pas pourquoi il affiche pas tout
merci pour ton aide
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 Private Sub QuoteCosting_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim ChaineConnexion As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source = Database2.accdb" Dim DtSet As New DataSet() Dim UneTable1 As New DataTable Dim UneTable2 As New DataTable Dim UneTable3 As New DataTable Dim UneTable4 As New DataTable Dim UneTable5 As New DataTable Dim cn1 As New OleDbDataAdapter("select distinct PN from tblToolRequisition Order by PN asc", ChaineConnexion) ' tblPN Dim cn2 As New OleDbDataAdapter("select distinct CustomerName from tblToolRequisition Order by CustomerName asc", ChaineConnexion) ' tblCustomer Dim cn3 As New OleDbDataAdapter("select distinct ToolDRG from tblToolRequisition Order by ToolDRG asc", ChaineConnexion) ' tblTool Dim cn4 As New OleDbDataAdapter("select distinct RequistionNum from tblToolRequisition Order by RequistionNum asc", ChaineConnexion) ' tblRequisition Dim cn5 As New OleDbDataAdapter("Select * from tblToolRequisition", ChaineConnexion) cn1.Fill(UneTable1) cn2.Fill(UneTable2) cn3.Fill(UneTable3) cn4.Fill(UneTable4) cn1.Fill(UneTable5) DtSet.Tables.Add(UneTable1) DtSet.Tables.Add(UneTable2) DtSet.Tables.Add(UneTable3) DtSet.Tables.Add(UneTable4) DtSet.Tables.Add(UneTable5) DtSet.Tables(0).TableName = "tblPN" DtSet.Tables(1).TableName = "tblCustomer" DtSet.Tables(2).TableName = "tblTool" DtSet.Tables(3).TableName = "tblRequisition" DtSet.Tables(4).TableName = "tblToolRequisition" DataGridView1.DataSource = DtSet.Tables("tblToolRequisition") ComboBox1.DataSource = DtSet.Tables("tblPN") ComboBox1.DisplayMember = "PN" ComboBox2.DataSource = DtSet.Tables("tblCustomer") ComboBox2.DisplayMember = "CustomerName" ComboBox3.DataSource = DtSet.Tables("tblTool") ComboBox3.DisplayMember = "ToolDRG" ComboBox4.DataSource = DtSet.Tables("tblRequisition") ComboBox4.DisplayMember = "RequistionNum" If ComboBox1.SelectedIndex Then Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() IndexColonne = 4 For IndexLigne = 0 To DataGridView1.Rows.Count - 1 Try If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox1.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Catch End Try Next ElseIf ComboBox2.SelectedIndex Then Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() IndexColonne = 3 For IndexLigne = 0 To DataGridView1.Rows.Count - 1 Try If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox2.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Catch End Try Next ElseIf ComboBox3.SelectedIndex Then Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() IndexColonne = 6 For IndexLigne = 0 To DataGridView1.Rows.Count - 1 Try If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox3.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Catch End Try Next ElseIf ComboBox4.SelectedIndex Then Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() IndexColonne = 1 For IndexLigne = 0 To DataGridView1.Rows.Count - 1 Try If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox4.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Catch End Try Next End If End Sub
Voici, j'ai trouvé l'erreur ...
Mais tu dois changer les sélections sur Combo d'endroit : une procédure événementielle par Combo (pour commencer). Ton code actuel, sur l'événement Load, ne s'exécutera pas lors des sélections sur combo.
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 Private Sub QuoteCosting_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load Dim ChaineConnexion As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source = Database2.accdb" Dim DtSet As New DataSet() Dim UneTable1 As New DataTable Dim UneTable2 As New DataTable Dim UneTable3 As New DataTable Dim UneTable4 As New DataTable Dim UneTable5 As New DataTable Dim cn1 As New OleDbDataAdapter("select distinct PN from tblToolRequisition Order by PN asc", ChaineConnexion) ' tblPN Dim cn2 As New OleDbDataAdapter("select distinct CustomerName from tblToolRequisition Order by CustomerName asc", ChaineConnexion) ' tblCustomer Dim cn3 As New OleDbDataAdapter("select distinct ToolDRG from tblToolRequisition Order by ToolDRG asc", ChaineConnexion) ' tblTool Dim cn4 As New OleDbDataAdapter("select distinct RequistionNum from tblToolRequisition Order by RequistionNum asc", ChaineConnexion) ' tblRequisition Dim cn5 As New OleDbDataAdapter("Select * from tblToolRequisition", ChaineConnexion) cn1.Fill(UneTable1) cn2.Fill(UneTable2) cn3.Fill(UneTable3) cn4.Fill(UneTable4) '' Voici l'erreur =========> cn1.Fill(UneTable5) ' et le corrigé : cn5.Fill(UneTable5) ' c'est peut-être moi ... les aléas des copier-coller :D))) DtSet.Tables.Add(UneTable1) DtSet.Tables.Add(UneTable2) DtSet.Tables.Add(UneTable3) DtSet.Tables.Add(UneTable4) DtSet.Tables.Add(UneTable5) DtSet.Tables(0).TableName = "tblPN" DtSet.Tables(1).TableName = "tblCustomer" DtSet.Tables(2).TableName = "tblTool" DtSet.Tables(3).TableName = "tblRequisition" DtSet.Tables(4).TableName = "tblToolRequisition" DataGridView1.DataSource = DtSet.Tables("tblToolRequisition") ComboBox1.DataSource = DtSet.Tables("tblPN") ComboBox1.DisplayMember = "PN" ComboBox2.DataSource = DtSet.Tables("tblCustomer") ComboBox2.DisplayMember = "CustomerName" ComboBox3.DataSource = DtSet.Tables("tblTool") ComboBox3.DisplayMember = "ToolDRG" ComboBox4.DataSource = DtSet.Tables("tblRequisition") ComboBox4.DisplayMember = "RequistionNum" '''**************Pour tout ce qui suit, il faut écrire autant de procédure événmentielle que de Combo ''' Private Sub Combo..._SelectedIndexChanged(ByVal sender As Object ... 'If ComboBox1.SelectedIndex Then ' Dim IndexColonne As Integer ' Dim IndexLigne As Integer ' DataGridView1.ClearSelection() ' IndexColonne = 4 ' For IndexLigne = 0 To DataGridView1.Rows.Count - 1 ' Try ' If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox1.Text Then ' DataGridView1.Rows(IndexLigne).Selected = True ' End If ' Catch ' End Try ' Next 'ElseIf ComboBox2.SelectedIndex Then ' Dim IndexColonne As Integer ' Dim IndexLigne As Integer ' DataGridView1.ClearSelection() ' IndexColonne = 3 ' For IndexLigne = 0 To DataGridView1.Rows.Count - 1 ' Try ' If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox2.Text Then ' DataGridView1.Rows(IndexLigne).Selected = True ' End If ' Catch ' End Try ' Next 'ElseIf ComboBox3.SelectedIndex Then ' Dim IndexColonne As Integer ' Dim IndexLigne As Integer ' DataGridView1.ClearSelection() ' IndexColonne = 6 ' For IndexLigne = 0 To DataGridView1.Rows.Count - 1 ' Try ' If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox3.Text Then ' DataGridView1.Rows(IndexLigne).Selected = True ' End If ' Catch ' End Try ' Next 'ElseIf ComboBox4.SelectedIndex Then ' Dim IndexColonne As Integer ' Dim IndexLigne As Integer ' DataGridView1.ClearSelection() ' IndexColonne = 1 ' For IndexLigne = 0 To DataGridView1.Rows.Count - 1 ' Try ' If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox4.Text Then ' DataGridView1.Rows(IndexLigne).Selected = True ' End If ' Catch ' End Try ' Next 'End If End Sub
ah non dsl c'est mon erreur
du coup pour les procedures evementielles je met les 4 if dans chaque ? pcq quand j'avais essayé un par un ca ne marchait, seul le combobox1 etait effectue
Si je me souviens bien, la procédure événementielle pour le ComboBox1 est :
Tu dois refaire la "même" procédure pour chacun des Combos, en adaptant le nom de la colonne pour l’obtention de l'IndexColonne : IndexColonne = DataGridView1.Columns("PN").Index
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim IndexColonne As Integer Dim IndexLigne As Integer If TemoinDBOuverte Then DataGridView1.ClearSelection() IndexColonne = DataGridView1.Columns("PN").Index For IndexLigne = 0 To DataGridView1.Rows.Count - 1 If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox1.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Next End If End Sub
Quand elles fonctionnent toutes, je veux bien te les grouper en une seule procédure ...
J'ai utilise l'autre version pour chaque comboboxSur celle que tu m'as donné juste avant il y a une erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() IndexColonne = 4 For IndexLigne = 0 To DataGridView1.Rows.Count - 1 Try If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox1.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Catch End Try Next End Sub
le probleme c'est que quand je selectionne dans les combobox, il ne selectionne aucune ligne
Dsl en fait ca marche
J'aurais jsute une derniere question concernant ces combobox: Est il possible de supprimer les lignes non selectionne? Par exemple, si je choisis le client 3 dans la combobox toutes les lignes qui ne concernent pas ce client s'efface et revienne si je choisis un autre client
J'ai regarde sur internet mais je trouve que des solutions qui supprime l'element qui est selectionné dans le combobox, l'inverse de ce que je veux
Finalement, est-ce la version (ci-dessous) avec les noms de colonnes qui fonctionne ?
Pour ce qui d'enlever les lignes et les remettre, ça revient à modifier la requête d’alimentation du DataGrigView (exemple pour les PN) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim IndexColonne As Integer Dim IndexLigne As Integer If TemoinDBOuverte Then DataGridView1.ClearSelection() IndexColonne = DataGridView1.Columns("PN").Index For IndexLigne = 0 To DataGridView1.Rows.Count - 1 If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox1.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Next End If End Sub
Mais il faut alors ré-initialiser le DataGridView1.DatdaSource, si je me souviens bien ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 ' Attention de ne pas oublier ' et " ... "select * from tblToolRequisition WHERE (PN = '" & ComboBox.Text & "')"
Attention qu'avec ce système, à partir de la première sélection, tu ne montres plus jamais l'entièreté des données ...
Non au final c'est celui avec le n° de colonne :
Je pense que l'etape de suppression des lignes je le ferais plus tard, je vais refaire des recherches
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 Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() IndexColonne = 4 For IndexLigne = 0 To DataGridView1.Rows.Count - 1 Try If DataGridView1.Item(IndexColonne, IndexLigne).Value = ComboBox1.Text Then DataGridView1.Rows(IndexLigne).Selected = True End If Catch End Try Next End Sub
Dans tout les cas, merci pour ton aide Phil Rob
Dommage que c'est avec le numéro de colonne, j'aurai pu faire plus court encore avec les noms de colonnes ..., mais voici une procédure événementielle de réponse au changement d'index d'un Combo qui suffit à elle seule pour tous les Combos dédiés à ± la même tâche (sélection des lignes ...) :
La ligne d'entête de la Sub est modifiée, il y a l'ajout d'un Select Case et une modification de l'alternative.
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 Private Sub LesComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged, ComboBox3.SelectedIndexChanged Dim IndexColonne As Integer Dim IndexLigne As Integer DataGridView1.ClearSelection() Select Case sender.name Case "ComboBox1" IndexColonne = 4 Case "ComboBox2" IndexColonne = .......... Case "ComboBox3" IndexColonne = ................. ' ... ... ... End Select For IndexLigne = 0 To DataGridView1.Rows.Count - 1 Try If DataGridView1.Item(IndexColonne, IndexLigne).Value = sender.Text Then ' !!! changement DataGridView1.Rows(IndexLigne).Selected = True End If Catch End Try Next End Sub
Quand tu veux réorganiser ton code, fais signe, j'ai un petit programme didactique qui montre l'exemple.
A bientôt,
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager