Bonjour,
Comment remplir une listview dynamiquement ?
Je veux remplir une ligne d'une listview a partir d'une base de donnée et qui respect une condition, c'est à dire par exemple si j'ai une ligne qui a 5 colonnes et plusieurs lignes. Si je veux fixer une ligne qui a une adresse égale à 2 par exemple et remplir ces champs par ces valeurs convenables.
J'ai essayé avec ce code mais ça marche pas.

Merci en avance.

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
 
 for (int i = 0; i < listView1.Items.Count; i++)
                {
                    d2 = 2;
                    if  (d2.ToString() == it[i].SubItems[1].Text)
                    {
                     try
                        {
                            Program.connexion.Open();
                            string mySelectQuery = "SELECT Live_Operation.Label ,Nbr_Lot,Start_Date,End_Date,Oven.Temperat_Con_1,Oven.Temperat_Max_1,Oven.Rise_Time_1,Oven.Time_Level_1,Oven.Temperat_Con_2,Oven.Adresse,Oven.Temperat_Max_2 FROM Live_Operation,Oven where Live_Operation.Label=Oven.Label ";
 
                            SqlCommand myCommand = new SqlCommand(mySelectQuery, Program.connexion);
                            SqlDataReader myReader = myCommand.ExecuteReader();
 
                            while (myReader.Read())
                            {
                                if (it[i].Text == myReader[0].ToString())
                                {
                                    it[i].SubItems[2].Text = ("ON");
                                    this.it[i].SubItems[0].ForeColor = Color.Pink;
                                     t[i].SubItems[3].Text= d2.tostring(); 
                                    it[i].SubItems[4].Text = myReader[1].ToString();
 
                                   it[i].SubItems[5].Text = myReader[2].ToString();
                                    it[i].SubItems[6].Text = myReader[3].ToString();
 
 
                                }
                            }
 
                        }
                        catch { }
 
                     }
                    else
                    {
                        it[i].SubItems[2].Text = ("NC");
                        this.it[i].SubItems[0].ForeColor = Color.Gold;
                    }
 
 
                }