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 :

C# + objet + windows form + datagridview


Sujet :

C#

  1. #1
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut C# + objet + windows form + datagridview
    Bonjour,

    voila j'ai un soucis,

    je cherche à remplir un datagridview donc jusque là pas de problème

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    datagridview.Rows.Add(...)
    le problème c'est que je cherche à le remplir avec cette valeur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ((Animaux)listAnimaux[j]).getPersonneEnCharge().getNom();
    problème c'est que getPersonnelEnCharge() est de type Personnel
    et getNom() est de type string.

    donc lorsque je met cette ligne dans datagrid.Rows.add()

    j'ai un message d'erreur

    la référence d'un objet n'est pas définie à une instance d'un objet.
    faut-il convertir l'objet en string ??

    Merci d'avance

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 208
    Points : 136
    Points
    136
    Par défaut
    es-tu sur que :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ((Animaux)listAnimaux[j]) != null
    que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ((Animaux)listAnimaux[j]).getPersonneEnCharge() != null
    et
    que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ((Animaux)listAnimaux[j]).getPersonneEnCharge().getNom() != null

  3. #3
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut
    Oui c'est bien != null

  4. #4
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Montre-nous le code complet de :
    datagridview.Rows.Add(...)
    Est-tu sur que tu as mis autant de valeurs que de colonnes ?

  5. #5
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut
    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
    if (((Animaux)listAnimaux[j]).getInNursery() == true)
                    {
                        
                        comboboxPersonnelAffecte.Items.Clear();
                        string type = ((Animaux)listAnimaux[j]).getType();
                        string nom = ((Animaux)listAnimaux[j]).getnom();
                        
    
                        dataGridViewInfi.Rows.Add(type, nom);         
    //J'aimerais ici rajouter le 3ème paramètre
    
    ((Animaux)listAnimaux[j]).getEnCharge().getnom();
    
    
                        for (int i = 0; i < listPersonnel.Count; i++)
                        {
                            string nomP = ((Personnel)listPersonnel[i]).getNom();
                            string prenom = ((Personnel)listPersonnel[i]).getPrenom();
                            string specialite = ((Personnel)listPersonnel[i]).getSpecialite();
                            bool etatPersonnel = ((Personnel)listPersonnel[i]).getInNursery();
                            
                            if (type == "Felin" && specialite == "Felin")
                            {
                                comboboxPersonnelAffecte.Items.Add(nomP + " " + prenom);
                            }
         
                         }
                         
                         if (((Animaux)listAnimaux[j]).getPersonneEnCharge() != null)
                         {
                            
                             MessageBox.Show("Animal " + nom + " Personnel Affecté= " +
                                             ((Animaux)listAnimaux[j]).getPersonneEnCharge().getNom());
                    
                         }
                         else
                         {
                             MessageBox.Show("Animal " + nom + "Aucun Personne affecté");
                              
                         }
                       
                    }
                
                }
    
            }

  6. #6
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut
    ba ma 4ème colonne c'est mes combobox donc j'ai mis aucune valeur

  7. #7
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Essaye d'ajouter une valeur pour la colonne 4, avec null ou alors LaComboBoxDeLaColonne4.items[0].

  8. #8
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut
    oui mais j'ai toujours le problème sur la référence d'objet

    la référence d'un objet n'est pas définie à une instance d'un objet.

  9. #9
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    dataGridViewInfi.Rows.Add(type, nom,((Animaux)listAnimaux[j]).getPersonneEnCharge().getNom(),null);
    et la deuxième solution que tu m'avais proposé

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    dataGridViewInfi.Rows.Add(type, nom,((Animaux)listAnimaux[j]).getPersonneEnCharge().getNom(),comboboxPersonnelAffecte.Items[0]);
    j'ai un message d'erreur
    invalid argument, la valeur 0 n'est pas valide pour l'index

  10. #10
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    comboboxPersonnelAffecte.Count ne devraitil pas être supérieur à 0 (contenir au moins un ou plusieurs choix) ?

  11. #11
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut
    si dans ma combobox j'ai toujours au moins un choix

  12. #12
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Verifie :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if (comboboxPersonnelAffecte.Items.Count==0) MessageBox.show("0 item") ;
    Si 0 items dans la combo :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    dataGridViewInfi.Rows.Add(type, nom,((Animaux)listAnimaux[j]).getPersonneEnCharge().getNom(),
    comboboxPersonnelAffecte.Items.Count==0?null : comboboxPersonnelAffecte.Items[0]);

  13. #13
    Membre régulier Avatar de florianjoy54
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    155
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 155
    Points : 91
    Points
    91
    Par défaut
    effectivement il y a bien 0 Items, et sa met l'erreur même quand je test si l'item est égal à 0

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ajouts en Masse [WPF] datagrid ou [Windows Form] Datagridview
    Par lerieure dans le forum Développement Windows
    Réponses: 0
    Dernier message: 05/12/2010, 13h58
  2. Réponses: 6
    Dernier message: 27/04/2009, 10h34
  3. [XAML/WPF] Equivalent du DataGridView des Windows Forms
    Par Nadd dans le forum Windows Presentation Foundation
    Réponses: 2
    Dernier message: 09/01/2008, 20h35
  4. Windows Form: impression d'un datagridview
    Par bensra dans le forum Windows Forms
    Réponses: 8
    Dernier message: 19/12/2007, 10h41
  5. Insérer dans du Web.UI un objet Windows.Form
    Par lilou77 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 11/06/2007, 15h17

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