Salut tout le monde,

je cherche à remplir une datagrid view avec les résultat d'un findAll() dans l'ad.

Pour m'aider j'ai suivi ce tuto: https://morpheus.developpez.com/ADDotnet/ADCSharp/
Le tuto est pour une application console eet moi je fais un Windows Form

Le problème que j'ai c'est que dans mon datagridview un seul résultat s'affiche. Par exemple je fais une recherche par nom 3 utilisateurs ont le même nom, je capte bien le nombre de résultat de la recherche mais mes 3 lignes sont remplies avec les infos d'un seul et même utilisateur.

Quelqu'un aurait une idée?

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
 
try
                    {
                        string RNom = row.Cells[1].Value.ToString();
 
 
 
 
                        DirectoryEntry ldapConnection = new DirectoryEntry("LDAP://mondomaine", login, mdp);
                        DirectorySearcher searcher = new DirectorySearcher(ldapConnection);
                        searcher.Filter = "(sn=" + RNom + ")";
 
                        foreach (SearchResult result in searcher.FindAll())
                        {
                            // On récupère l'entrée trouvée lors de la recherche
 
 DirectoryEntry DirEntry = result.GetDirectoryEntry();
 
                            //On  affiche les informations désirées
 
 
                            //Si plusieurs résultats à la recherche ouvre une datagrid pour selectionner l'utilisateur souhaité
                            if (searcher.FindAll().Count > 1)
                            {
                                dataGridView1.Visible = true;
                                dataGridView1.RowCount = searcher.FindAll().Count;
 
 
 
                                foreach (DataGridViewRow rows in dataGridView1.Rows)
                                {
 
 
                                    rows.Cells[0].Value = DirEntry.Properties["SAMAccountName"].Value.ToString();
                                    rows.Cells[1].Value = DirEntry.Properties["sn"].Value.ToString();
                                    rows.Cells[2].Value = DirEntry.Properties["givenName"].Value.ToString();
                                }
 
 
                            }
                        }
                    }