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 :

Ecriture dans une DataGridViewComboBoxColumn


Sujet :

C#

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Avril 2010
    Messages : 31
    Points : 29
    Points
    29
    Par défaut Ecriture dans une DataGridViewComboBoxColumn
    Bonjour à tous
    Déjà merci a tous de me lire et encore un merci a ceux qui tenterons de m'aider ^^

    Voici mon problème:

    J'ai un datagridview auquel j'ajoute une colonne de type DataGridViewComboBoxColumn elle est remplis a l'aide d'une liste.
    j'ai certaine cellule de cette colonne qui sont fournis par Calcule lors d'un changement dans une autre cellule et je souhaiterais ne pas avoir a intégrer dans ma liste toute les possibilités de ce calcule.
    J'ai trouvé 2 solutions a ce problème:
    Sol1: Permettre l'écriture dans la column
    Sol2: Que la cellule de calcule ne soit pas de type combobox

    Si quelqu'un peux m'aider pour répondre a au moins une des question je lui en serais très reconnaissant.

    Merci beaucoup et bonne journée
    Tom

  2. #2
    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
    Bonjour,

    Si la colonne est "bindée" (à une liste ou à une DataTable), il ne sera pas possible de saisir une valeur ne figurant pas dans la liste/table sans bidouiller.

    Regarde cette discussion sur ce sujet :
    http://www.developpez.net/forums/d10...-datagridview/

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Avril 2010
    Messages : 31
    Points : 29
    Points
    29
    Par défaut
    Je te remercie j'essaye ca et je vous tien au courant
    Bonne journée
    Tom

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Avril 2010
    Messages : 31
    Points : 29
    Points
    29
    Par défaut
    C'est parfait un peux de bidouille supplémentaire et ca marche
    Merci bcp

    Pour ceux qui cherche je donne ma soluce
    petit rappel je souhaitais pouvoir modifier une datagridviewcomboboxcolumn et effectuer un calcule avec celle ci qui apparaitrais dans une autre cellule

    voici mes 3 fonctions qui m'ont permis d'arriver a ca
    c'est pas forcement le code le plus propre mais bon c'est déjà ca ^^

    il faut avant tous crée les différents évènement a la création du datagridview qui sont:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
                    tdata[w].CellValueChanged += new DataGridViewCellEventHandler(cellchange);
                    tdata[w].EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(EditGridView_ControlShowing);
                    tdata[w].CellValidating += new DataGridViewCellValidatingEventHandler(EditGridView_CellValidating);
                    //tdata[w].DataError += new DataGridViewDataErrorEventHandler(GridView_DataError);

    et ensuite il faut ces fonctions


    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
            private void cellchange(object sender, System.EventArgs e)
            {
     
                bool b = ((System.Windows.Forms.Control)(sender)).Name.Contains("traction");
                if (b == true)
                {
                    String z = ((System.Windows.Forms.Control)(sender)).Name.Remove(0, 8);
                    int v = int.Parse(z);
                    if (tlabel8[v].Text == "Traction")
                    {
                        if (tdata[v].CurrentCell.ColumnIndex == 0)
                        {
                            DataGridView Dgv = (DataGridView)sender;
     
                            DataGridViewComboBoxColumn DgvCbCol = (DataGridViewComboBoxColumn)Dgv.Columns[0];
                            if (tdata[v].CurrentCell.RowIndex == 0)
                            {
                                // on rajoute la valeur saisie aux items du ComboBox
     
                                if (DgvCbCol.Items.Contains(tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value))
                                {
                                    tdata[v].Rows[2].Cells[0].Value = tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value;
                                }
                                else
                                {
                                    DgvCbCol.Items.Add(tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value);
                                    tdata[v].Rows[2].Cells[0].Value = tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value;
                                }
                                if (suprimer != null)
                                {
                                    DgvCbCol.Items.Remove(suprimer.ToString());
                                    suprimer = null;
                                }
     
                            }
                            if (tdata[v].CurrentCell.RowIndex == 1)
                            {
                                // on rajoute la valeur saisie aux items du ComboBox
                                if (DgvCbCol.Items.Contains(tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value))
                                {
                                    tdata[v].Rows[2].Cells[0].Value = tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value;
                                }
                                else
                                {
                                    DgvCbCol.Items.Add(tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value);
                                    tdata[v].Rows[2].Cells[0].Value = tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value;
                                }
                                if (suprimer != null)
                                {
                                    DgvCbCol.Items.Remove(suprimer.ToString());
                                    suprimer = null;
                                }
     
                            }
                        }
     
     
                    }
     
     
                }
            }
            private void EditGridView_ControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                if (e.Control.GetType() == typeof(DataGridViewComboBoxEditingControl))
                {
                    DataGridViewComboBoxEditingControl Cb = (DataGridViewComboBoxEditingControl)e.Control;
                    Cb.DropDownStyle = ComboBoxStyle.DropDown;
                    DataGridView Dgv = (DataGridView)sender;
                                bool b = ((System.Windows.Forms.Control)(sender)).Name.Contains("traction");
    if (b == true)
                    suprimer = Dgv.Rows[2].Cells[0].Value.ToString();
                }
            }
            private void EditGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
            {
                DataGridView Dgv = (DataGridView)sender;
                if (Dgv.Columns[e.ColumnIndex].GetType() == typeof(DataGridViewComboBoxColumn))
                {
                    DataGridViewComboBoxColumn DgvCbCol = (DataGridViewComboBoxColumn)Dgv.Columns[e.ColumnIndex];
                    try
                    { // on rajoute la valeur saisie qaux items du ComboBox
                        Object Value = Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].ParseFormattedValue(e.FormattedValue, DgvCbCol.DefaultCellStyle, null, null);
                        if (DgvCbCol != null && Value != null && e.FormattedValue.ToString() != "" && !DgvCbCol.Items.Contains(e.FormattedValue)) DgvCbCol.Items.Add(Value);
                        Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Value;
                    }
                    catch
                    {
                        MessageBox.Show("Invalid value provided for column " + Dgv.Columns[e.ColumnIndex].Name + " :" + e.FormattedValue.ToString());
                        e.Cancel = true;
                    }
     
                }
            }
            //private void GridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
            //{
            //    DataGridView Dgv = (DataGridView)sender;
            //    if (e.Exception.Message.ToString().Contains("DataGridViewComboBox"))
            //    {
            //        Dgv.CurrentCell.Value = DBNull.Value;
            //    }
            //    else MessageBox.Show(e.Exception.Message.ToString());
            //    e.Cancel = true;
            //}
     
     
            private void CellValidating(object sender , DataGridViewCell e)
            {
                DataGridView Dgv = (DataGridView)sender;
                if (Dgv.Columns[e.ColumnIndex].GetType() == typeof(DataGridViewComboBoxColumn))
                {
                    DataGridViewComboBoxColumn DgvCbCol = (DataGridViewComboBoxColumn)Dgv.Columns[e.ColumnIndex];
                    try
                    { // on rajoute la valeur saisie aux items du ComboBox
                        Object Value = Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].ParseFormattedValue(e.FormattedValue, DgvCbCol.DefaultCellStyle, null, null);
                        if (DgvCbCol != null && Value != null && e.FormattedValue.ToString() != "" && !DgvCbCol.Items.Contains(e.FormattedValue)) DgvCbCol.Items.Add(Value.ToString() + Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                        Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (Value.ToString() + Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                        return;
                    }
                    catch
                    {
                        MessageBox.Show("Invalid value provided for column " + Dgv.Columns[e.ColumnIndex].Name + " :" + e.FormattedValue.ToString());
     
                    }
     
                }
            }


    Bonne journée a tous ;-)

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

Discussions similaires

  1. ecriture dans une textbox excel
    Par lensois62 dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 20/06/2006, 12h34
  2. Ecriture dans une fenêtre
    Par Corpio dans le forum GLUT
    Réponses: 5
    Dernier message: 22/05/2006, 14h15
  3. Probleme d'ecriture dans une base access
    Par mohamed_simo dans le forum ASP
    Réponses: 5
    Dernier message: 05/04/2006, 09h55
  4. [JDBC]lecture/ecriture dans une base de donnée
    Par tarik75 dans le forum JDBC
    Réponses: 7
    Dernier message: 30/06/2005, 12h42
  5. fonction ecriture dans une table
    Par smbpopov33 dans le forum Access
    Réponses: 5
    Dernier message: 20/06/2005, 14h52

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