IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Erreur foreach bizarre


Sujet :

C#

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2017
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2017
    Messages : 44
    Points : 34
    Points
    34
    Par défaut Erreur foreach bizarre
    Bonjour, je travaille actuellement sur un projet avec visual studio, et j'ai un problème concernant l'affichage d'un produit dans un DataGrid après la sélection d'un fournisseur dans un comboBox.
    Voici le code de mon formulaire :
    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
     
    using ClassLibraryL3B;
    using les3belges;
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using System.Collections;
    using gestionPriseCommande;
    using System.Linq;
     
    namespace gestionPriseCommande
    {
        public partial class FormProduitFournisseur : Form
        {
        public FormProduitFournisseur()
            {
                InitializeComponent();
            }
     
    private void FormProduitFournisseur_Load(object sender, EventArgs e)
            {
                List<Fournisseur> maListe = Passerelle.getLesFournisseursByNom();
     
                foreach (Fournisseur unFour in maListe)
                {
                    comboBox2.Items.Add(unFour.getNomFournisseur());
                }
            }
     
            private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
            {
                dataGridView1.Visible = true;
                string unNomFournisseur = comboBox2.Text;
                list<Produit> lesProduits = Passerelle.getLesProduitByNom();
                foreach (Produit unProd in lesProduits)
                {
                    string prixUHTProduit = null;
                    string[] ligne = {ReferenceProduit.ToString(),LibelleProduit.ToString(),prixUHTProduit,StockTheorique.ToString(),TauxTVA.ToString(),StockTemp.ToString(),CouleurProduit.ToString(),TailleProduit.ToString(),OrigineProduit.ToString(),DelaiReapro.ToString(),SeuilReapro.ToString()};
                    dataGridView1.Rows.Add(ligne);
                }
            }
    }
    }
    Et le code de ma passerelle qui contient la fonction qui récupère les data de ma table "produit" pour les afficher dans le 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
     using gestionPriseCommande;
    using les3belges;
    using ProjLibraryClassReq;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Collections;
    using ClassLibraryL3B;
    using System.Windows.Forms;      
    //fonction permettant de récupérer tous les produits d'un fournisseur
            public static List<Produit> getLesProduitsByNom()
            {
                List<Produit> maListe = new List<Produit>();
                Produit unObjFournisseur = null;
                if (ClassReq.RetConnOk() == true)
                {
                    ClassReq afficherClasse = new ClassReq("SELECT * FROM PRODUIT "); // creer une nouvelle requete
                    DataTable resultat = new DataTable();
                    resultat = afficherClasse.ExecuteSelect(); // recupere le resultat de la requete
                    foreach (DataRow resLigne in resultat.Rows)
                    {
                        string referenceProd = resLigne["referenceProd"].ToString();
                        string libelleProduit = resLigne["libelleProduit"].ToString();
                        double prixUHT = Double.Parse(resLigne["prixUHT"].ToString());
                        double tauxTVA = Double.Parse(resLigne["tauxTVA"].ToString());
                        int seuilReapro = Int32.Parse(resLigne["seuilReapro"].ToString());
                        int delaiReapro = Int32.Parse(resLigne["delaiReapro"].ToString());
                        int stockTemp = Int32.Parse(resLigne["stockTemp"].ToString());
                        string origineProduit = resLigne["origineProduit"].ToString();
                        string couleurProduit = resLigne["couleurProduit"].ToString();
                        string tailleProduit = resLigne["tailleProduit"].ToString();
                        int stockTheorique = Int32.Parse(resLigne["stockTheorique"].ToString());
                        int numFournisseur = Int32.Parse(resLigne["numFournisseur"].ToString());
                        int numCategorie = Int32.Parse(resLigne["numCategorie"].ToString());
                        string numReduction = resLigne["numReduction"].ToString();
                        string nomFournisseur = resLigne["nomFournisseur"].ToString();
                        unObjFournisseur = new Produit(referenceProd, libelleProduit, prixUHT, stockTheorique, tauxTVA, stockTemp, couleurProduit, tailleProduit, origineProduit, delaiReapro, seuilReapro, nomFournisseur);
                        maListe.Add(unObjFournisseur);
                    }
                }
                return maListe;
            }
    Et l'erreur avec plus de pertinence :
    L'instruction foreach ne peut pas fonctionner sur des variables de type 'gestionPriseCommande.list<les3belges.Produit>', car 'gestionPriseCommande.list<les3belges.Produit>' ne contient pas de définition publique pour 'GetEnumerator' gestionPriseCommande F:\L3BV1\NEWsol_gestionPriseCommande - Les3Belges\gestionPriseCommande\FormProduitFournisseur.cs ligne 50
    Merci d'avance de votre aide !

  2. #2
    Membre expérimenté
    Homme Profil pro
    Développeur .Net / Delphi
    Inscrit en
    Juillet 2002
    Messages
    738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur .Net / Delphi
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2002
    Messages : 738
    Points : 1 745
    Points
    1 745
    Par défaut
    Bonjour,
    Je suis étonné que cette ligne ne pose pas de problème :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    list<Produit> lesProduits = Passerelle.getLesProduitByNom();
    A priori la méthode doit retourner une List<Produit> qui sera stockée dans une list<Produit>

    ça ne râle pas ?

  3. #3
    Expert éminent sénior

    Avatar de François DORIN
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Juillet 2016
    Messages
    2 757
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2016
    Messages : 2 757
    Points : 10 697
    Points
    10 697
    Billets dans le blog
    21
    Par défaut
    Bonjour,

    A vue de nez, je dirais que tu as une classe générique List<T> qui est définie dans l'espace de nom gestionPriseCommande qui vient masquer celle définie dans System.Collections.Generic. Et ta classe générique n'implémente pas l'interface IEnumerable, d'où l'erreur rencontrée.
    François DORIN
    Consultant informatique : conception, modélisation, développement (C#/.Net et SQL Server)
    Site internet | Profils Viadéo & LinkedIn
    ---------
    Page de cours : fdorin.developpez.com
    ---------
    N'oubliez pas de consulter la FAQ C# ainsi que les cours et tutoriels

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2017
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2017
    Messages : 44
    Points : 34
    Points
    34
    Par défaut Problème
    Merci de votre aide, j'ai réussi à résoudre mon problème, désormais il n'y a aucune erreur.
    Mais ce qui est affiché dans le Datagrid n'est pas du tout ce que je veux, car je veux qu'il s'affiche toutes les données correspondants aux produits du fournisseur de la base de données ( par exemple : RefP1, Pull, Bleu, 15e,.... )


    Voici ce qui est affiché dans mon Datagrid :
    Nom : CaptureDatagrid.PNG
Affichages : 196
Taille : 50,5 Ko
    Dans chaque cellule, le contenu est (exemple ligne 1, colonne 1) :
    DataGridViewTextBoxColumn { Name=ReferenceProduit, Index=0 }
    Ligne 1, colonne 2 :
    DataGridViewTextBoxColumn { Name=ReferenceProduit, Index=1 }

    Code du formulaire :
    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
    using ClassLibraryL3B;
    using les3belges;
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using System.Collections;
    using gestionPriseCommande;
    using System.Linq;
     
    namespace gestionPriseCommande
    {
     
        public partial class FormProduitFournisseur : Form
        {
     
        public FormProduitFournisseur()
            {
                InitializeComponent();
            }
     
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
     
            }
     
            private void button3_Click(object sender, EventArgs e)
            {
     
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                this.Close();
            }
     
            private void FormProduitFournisseur_Load(object sender, EventArgs e)
            {
                List<Fournisseur> maListe = Passerelle.getLesFournisseursByNom();
     
                foreach (Fournisseur unFour in maListe)
                {
                    comboBox2.Items.Add(unFour.getNomFournisseur());
                }
            }
     
            private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
            {
                dataGridView1.Visible = true;
                string unNomFournisseur = comboBox2.Text;
                List<Produit> lesProduits = Passerelle.getLesProduitsByNom();
                foreach (Produit unProd in lesProduits)
                {
                    string[] ligne = {ReferenceProduit.ToString(),LibelleProduit.ToString(),PrixUHT.ToString(), StockTheorique.ToString(),TauxTVA.ToString(),StockTemp.ToString(),CouleurProduit.ToString(),TailleProduit.ToString(),OrigineProduit.ToString(),DelaiReapro.ToString(),SeuilReapro.ToString()};
                    dataGridView1.Rows.Add(ligne);
                }
            }
        }
    }
    Code de ma fonction dans le fichier passerelle qui SELECT les fournisseurs liés à un produit sélectionné dans le 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
    26
    27
    28
    29
    30
    31
    32
            public static List<Produit> getLesProduitsByNom()
            {
                List<Produit> maListe = new List<Produit>();
                Produit unObjFournisseur = null;
                if (ClassReq.RetConnOk() == true)
                {
                    ClassReq afficherClasse = new ClassReq("SELECT * FROM PRODUIT "); // creer une nouvelle requete
                    DataTable resultat = new DataTable();
                    resultat = afficherClasse.ExecuteSelect(); // recupere le resultat de la requete
                    foreach (DataRow resLigne in resultat.Rows)
                    {
                        string referenceProd = resLigne["referenceProd"].ToString();
                        string libelleProduit = resLigne["libelleProduit"].ToString();
                        double prixUHT = Double.Parse(resLigne["prixUHT"].ToString());
                        double tauxTVA = Double.Parse(resLigne["tauxTVA"].ToString());
                        int seuilReapro = Int32.Parse(resLigne["seuilReapro"].ToString());
                        int delaiReapro = Int32.Parse(resLigne["delaiReapro"].ToString());
                        int stockTemp = Int32.Parse(resLigne["stockTemp"].ToString());
                        string origineProduit = resLigne["origineProduit"].ToString();
                        string couleurProduit = resLigne["couleurProduit"].ToString();
                        string tailleProduit = resLigne["tailleProduit"].ToString();
                        int stockTheorique = Int32.Parse(resLigne["stockTheorique"].ToString());
                        int numFournisseur = Int32.Parse(resLigne["numFournisseur"].ToString());
                        int numCategorie = Int32.Parse(resLigne["numCategorie"].ToString());
                        string numReduction = resLigne["numReduction"].ToString();
                        string nomFournisseur = resLigne["nomFournisseur"].ToString();
                        unObjFournisseur = new Produit(referenceProd, libelleProduit, prixUHT, stockTheorique, tauxTVA, stockTemp, couleurProduit, tailleProduit, origineProduit, delaiReapro, seuilReapro, nomFournisseur);
                        maListe.Add(unObjFournisseur);
                    }
                }
                return maListe;
            }

  5. #5
    Membre expérimenté
    Homme Profil pro
    Développeur .Net / Delphi
    Inscrit en
    Juillet 2002
    Messages
    738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur .Net / Delphi
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2002
    Messages : 738
    Points : 1 745
    Points
    1 745
    Par défaut
    Bonjour,

    Dans la boucle Foreach, l'instance unProd n'est pas utilisée pour remplir le Row du DatagridView. Le problème vient de là. Tu utilises ReferenceProduit, LibelleProduit etc. mais on ne voit pas où ces variables sont définies.
    (Pour info, inutile de faire une ToString() sur une donnée de type String).

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2017
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2017
    Messages : 44
    Points : 34
    Points
    34
    Par défaut
    Merci de votre réponse, en effet je n'ai pas fourni le code de mon fichier du formulaire FormProduitFournisseur.designer.cs, où les variables ReferenceProduit, LibelleProduit, ... ont été définies en tant que nom de colonne pour le 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
    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    namespace gestionPriseCommande
    {
        partial class FormProduitFournisseur
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
     
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
     
            #region Windows Form Designer generated code
     
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.dataGridView1 = new System.Windows.Forms.DataGridView();
                this.ReferenceProduit = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.LibelleProduit = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.PrixUHT = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.StockTheorique = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.TauxTVA = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.StockTemp = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.CouleurProduit = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.TailleProduit = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.OrigineProduit = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.DelaiReapro = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.SeuilReapro = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.button3 = new System.Windows.Forms.Button();
                this.label11 = new System.Windows.Forms.Label();
                this.comboBox2 = new System.Windows.Forms.ComboBox();
                this.button1 = new System.Windows.Forms.Button();
                ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
                this.SuspendLayout();
                // 
                // dataGridView1
                // 
                this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
                this.ReferenceProduit,
                this.LibelleProduit,
                this.PrixUHT,
                this.StockTheorique,
                this.TauxTVA,
                this.StockTemp,
                this.CouleurProduit,
                this.TailleProduit,
                this.OrigineProduit,
                this.DelaiReapro,
                this.SeuilReapro});
                this.dataGridView1.Location = new System.Drawing.Point(35, 86);
                this.dataGridView1.Name = "dataGridView1";
                this.dataGridView1.Size = new System.Drawing.Size(1144, 141);
                this.dataGridView1.TabIndex = 0;
                this.dataGridView1.Visible = false;
                this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
                // 
                // ReferenceProduit
                // 
                this.ReferenceProduit.HeaderText = "ReferenceProduit";
                this.ReferenceProduit.Name = "ReferenceProduit";
                // 
                // LibelleProduit
                // 
                this.LibelleProduit.HeaderText = "LibelleProduit";
                this.LibelleProduit.Name = "LibelleProduit";
                // 
                // PrixUHT
                // 
                this.PrixUHT.HeaderText = "PrixUHT";
                this.PrixUHT.Name = "PrixUHT"; // 
                // StockTheorique
                // 
                this.StockTheorique.HeaderText = "StockTheorique";
                this.StockTheorique.Name = "StockTheorique";
                // 
                // TauxTVA
                // 
                this.TauxTVA.HeaderText = "TauxTVA";
                this.TauxTVA.Name = "TauxTVA";
                // 
                // StockTemp
                // 
                this.StockTemp.HeaderText = "StockTemp";
                this.StockTemp.Name = "StockTemp";
                // 
                // CouleurProduit
                // 
                this.CouleurProduit.HeaderText = "CouleurProduit";
                this.CouleurProduit.Name = "CouleurProduit";
                // 
                // TailleProduit
                // 
                this.TailleProduit.HeaderText = "TailleProduit";
                this.TailleProduit.Name = "TailleProduit";
                // 
                // OrigineProduit
                // 
                this.OrigineProduit.HeaderText = "OrigineProduit";
                this.OrigineProduit.Name = "OrigineProduit";
                // 
                // DelaiReapro
                // 
                this.DelaiReapro.HeaderText = "DelaiReapro";
                this.DelaiReapro.Name = "DelaiReapro";
                // 
                // SeuilReapro
                // 
                this.SeuilReapro.HeaderText = "SeuilReapro";
                this.SeuilReapro.Name = "SeuilReapro";
                // 
                // button3
                // 
                this.button3.Location = new System.Drawing.Point(662, 11);
                this.button3.Name = "button3";
                this.button3.Size = new System.Drawing.Size(100, 21);
                this.button3.TabIndex = 52;
                this.button3.Text = "Valider";
                this.button3.UseVisualStyleBackColor = true;
                this.button3.Click += new System.EventHandler(this.button3_Click);
                // 
                // label11
                // 
                this.label11.AutoSize = true;
                this.label11.Location = new System.Drawing.Point(375, 15);
                this.label11.Name = "label11";
                this.label11.Size = new System.Drawing.Size(102, 13);
                this.label11.TabIndex = 51;
                this.label11.Text = "Choix du fournisseur";
                // 
                // comboBox2
                // 
                this.comboBox2.FormattingEnabled = true;
                this.comboBox2.Location = new System.Drawing.Point(489, 12);
                this.comboBox2.Name = "comboBox2";
                this.comboBox2.Size = new System.Drawing.Size(121, 21);
                this.comboBox2.TabIndex = 50;
                this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(812, 11);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(100, 21);
                this.button1.TabIndex = 53;
                this.button1.Text = "Retour";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // FormProduitFournisseur
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(1284, 262);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.button3);
                this.Controls.Add(this.label11);
                this.Controls.Add(this.comboBox2);
                this.Controls.Add(this.dataGridView1);
                this.Name = "FormProduitFournisseur";
                this.Text = "Produit(s) d\'un fournisseur";
                this.Load += new System.EventHandler(this.FormProduitFournisseur_Load);
                ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
                this.ResumeLayout(false);
                this.PerformLayout();
     
            }
     
            #endregion
     
            private System.Windows.Forms.DataGridView dataGridView1;
            private System.Windows.Forms.DataGridViewTextBoxColumn ReferenceProduit;
            private System.Windows.Forms.DataGridViewTextBoxColumn LibelleProduit;
            private System.Windows.Forms.DataGridViewTextBoxColumn PrixUHT;
            private System.Windows.Forms.DataGridViewTextBoxColumn StockTheorique;
            private System.Windows.Forms.DataGridViewTextBoxColumn TauxTVA;
            private System.Windows.Forms.DataGridViewTextBoxColumn StockTemp;
            private System.Windows.Forms.DataGridViewTextBoxColumn CouleurProduit;
            private System.Windows.Forms.DataGridViewTextBoxColumn TailleProduit;
            private System.Windows.Forms.DataGridViewTextBoxColumn OrigineProduit;
            private System.Windows.Forms.DataGridViewTextBoxColumn DelaiReapro;
            private System.Windows.Forms.DataGridViewTextBoxColumn SeuilReapro;
            private System.Windows.Forms.Button button3;
            private System.Windows.Forms.Label label11;
            private System.Windows.Forms.ComboBox comboBox2;
            private System.Windows.Forms.Button button1;
        }
    }
    Merci d'avance !

  7. #7
    Membre expérimenté
    Homme Profil pro
    Développeur .Net / Delphi
    Inscrit en
    Juillet 2002
    Messages
    738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur .Net / Delphi
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2002
    Messages : 738
    Points : 1 745
    Points
    1 745
    Par défaut
    D'accord. Donc tu tentes de mettre des DataGridViewTextBoxColumn dans les lignes du DataGridView... Ca ne va pas bien fonctionner !
    Un peu d'aide en reprenant ton code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     foreach (Produit unProd in lesProduits)
      {
         string[] ligne = {unProd.ReferenceProduit,unProd.LibelleProduit,....};
         dataGridView1.Rows.Add(ligne);
      }
    D'ailleurs un Row (class DataGridViewRow) a une propriété Tag qui te permet de stocker n'importe quoi. Il pourrait être intéressant d'y stocker ton Produit afin de pouvoir le retrouver par la suite, lorsque l'utilisateur sélectionne la ligne par exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     foreach (Produit unProd in lesProduits)
      {
         string[] ligne = {unProd.ReferenceProduit,unProd.LibelleProduit,....};
         dataGridView1.Rows[dataGridView1.Rows.Add(ligne)].Tag = unProd;
      }
    (Il y a peut-être plus efficace mais j'avoue ne jamais avoir joué avec les DataGridView en WinForm)

  8. #8
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2017
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2017
    Messages : 44
    Points : 34
    Points
    34
    Par défaut
    C'était bien ça l'erreur, l'objet unProd était vide, j'ai réglé mon problème, merci à vous

Discussions similaires

  1. Message d'erreur assez bizarre reportant à un nombre de ligne inexistant
    Par beegees dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 21/02/2007, 15h19
  2. erreur très bizarre
    Par sandytarit dans le forum Environnement de Développement Intégré (EDI)
    Réponses: 1
    Dernier message: 16/01/2007, 17h00
  3. [SQL] Problème erreur sql bizarre
    Par baleiney dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 28/06/2006, 12h31
  4. [DOM] Erreur vraiment bizarre ...
    Par _beber85 dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 21/04/2006, 08h29
  5. [JDBC] Erreur très bizarre dans ExecuteQuery
    Par boudou dans le forum JDBC
    Réponses: 6
    Dernier message: 17/03/2006, 18h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo