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

Windows Forms Discussion :

DataGridView avec cellules en listbox


Sujet :

Windows Forms

  1. #1
    Membre habitué
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2009
    Messages
    236
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 236
    Points : 133
    Points
    133
    Par défaut DataGridView avec cellules en listbox
    Bonjour,

    Je dois remplir un DataGridView manuellement à partir d'un Array.

    J'ai bien suivi le tuto de msdn pour remplir le grid manuellement soit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    string[] row = { "nomChamp","Valeur" };
    this.GridPropsOccObjet.Rows.Add(row);
    Je n'ai que 2 colonnes dans le gridView que j'ai crée par contre pour certain champ j'aimerais que la cellule de ma deuxième colonne soit une listbox car plusieurs valeurs possibles et fixes.

    mon Array ressemble a ça :
    NomChamp1, Valeur1
    NomChamp2, Valeur2
    NomChamp3, val1;val2;val3;val4
    ...
    val1;val2;val3;val4 est une string séparée par des ;

    Comment puis-je faire ?

    Merci pour votre aide
    La Solution AGILE de Cartographie et d'Urbanisation des Systèmes d'Information éditée et développée par la société AB+ SOFTWARE
    https://www.abplussoftware.fr

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 749
    Points
    39 749
    Par défaut
    Ca doit être possible, mais pas très facile...
    Il y a un exemple sur MSDN, où ils montrent comment créer une colonne DateTimePicker pour afficher/éditer des dates. En adaptant un peu, tu dois pouvoir obtenir ce que tu veux...

  3. #3
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2010
    Messages
    479
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

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

    Informations forums :
    Inscription : Août 2010
    Messages : 479
    Points : 762
    Points
    762
    Par défaut
    La colonne 3 doit-elle supporter un choix multiple ou unique ?
    Si c'est un choix unique du type :
    var 1
    var 2
    var 3
    var 4
    je sélectionne 1 ligne parmi les 4 une DataGridViewComboBoxCell suffit.

    Au contraire si tu veux pouvoir cocher plusieurs éléments (au moins deux ligne parmi les 4) dans ta liste oriente toi vers la solution proposée par tomlev.

    hf

  4. #4
    Membre habitué
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2009
    Messages
    236
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 236
    Points : 133
    Points
    133
    Par défaut
    non la cellule est a choix unique, en fait je sais pas comment faire pour avoir dans la même colonne du gridview des cellules textbox et des cellules listbox
    La Solution AGILE de Cartographie et d'Urbanisation des Systèmes d'Information éditée et développée par la société AB+ SOFTWARE
    https://www.abplussoftware.fr

  5. #5
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2010
    Messages
    479
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

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

    Informations forums :
    Inscription : Août 2010
    Messages : 479
    Points : 762
    Points
    762
    Par défaut
    Re-bonjour;
    pour mixer le type de celulle tu dois le faire toi même.
    Petit exemple :
    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
      //dgv est le Datagridview je lui ajoute deux colonne sans spécifiquer le type
                dgv.Columns.Add("col_1", "juste du texte");
                dgv.Columns.Add("col_2", "texte et listes");
     
                //ajout de la 1ere ligne (deux textboxes)
                DataGridViewRow row_1 = new DataGridViewRow();
                DataGridViewTextBoxCell tbc_1 = new DataGridViewTextBoxCell();
                tbc_1.Value = "1-1";
                DataGridViewTextBoxCell tbc_2 = new DataGridViewTextBoxCell();
                tbc_2.Value = "1-2";
                row_1.Cells.Add(tbc_1);
                row_1.Cells.Add(tbc_2);
                dgv.Rows.Add(row_1);
     
                //ajout de la 2nde ligne (une textbox et une combobox (liste))
                DataGridViewRow row_2 = new DataGridViewRow();
                DataGridViewTextBoxCell tbc_3 = new DataGridViewTextBoxCell();
                tbc_3.Value = "2-1";
                DataGridViewComboBoxCell cbc = new DataGridViewComboBoxCell();
                cbc.Items.Add("var 1");
                cbc.Items.Add("var 2");
                cbc.Items.Add("var 3");
                cbc.Items.Add("var 4");
                row_2.Cells.Add(tbc_3);
                row_2.Cells.Add(cbc);
                dgv.Rows.Add(row_2);
    En espérant que cela t'aide.

  6. #6
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut un ListBoxColumn ou un CheckedListBoxColumn dans un datagridview
    Bonjour lead8209
    Beaucoup de question à ce que je constates sur le forum à propos de l'utilisation du DataGridView.
    La personnalisation du DataGridView n'est pas chose de tout repos comme l'a souligne si bien TomLev.
    Quoique ton utilisation d'un tableau me parait peu orthodoxe.
    En fait c'est 2 listes qu'il te faudrait :un element de la premiere pointant sur la 2eme liste.
    Bref voici un exemple de personnalisation du controle CheckedListBoxColumn
    code csharp du CheckedListBoxColumn :
    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
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
     
    // La classe CheckedListBoxColumn
    using System;
    using System.Windows.Forms;
    using System.Drawing.Design;
    using System.ComponentModel;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    namespace DataGridViewListBoxCSharp
    {
     
     
        public class CheckedListBoxColumn : System.Windows.Forms.DataGridViewColumn   
        {   
            public CheckedListBoxColumn()   
                : base(new CheckedListBoxCell())   
            {   
            }   
     
            public override DataGridViewCell CellTemplate   
            {   
                get   
                {   
                    return base.CellTemplate;   
                }   
                set   
                {                  
                    if (value != null &&   
                        !value.GetType().IsAssignableFrom(typeof(CheckedListBoxCell)))   
                    {   
                        throw new InvalidCastException("Must be a CheckedListBoxCell");   
                    }   
                    base.CellTemplate = value;   
                }   
            }   
        }   
     
        public class CheckedListBoxCell : DataGridViewCell   
        {   
            public CheckedListBoxCell()   
                : base()   
            {   
     
            }   
     
            public override void InitializeEditingControl(int rowIndex, object   
                initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)   
            {   
                // Set the value of the editing control to the current cell value.   
                base.InitializeEditingControl(rowIndex, initialFormattedValue,   
                    dataGridViewCellStyle);   
                CheckedListBoxEditingControl ctl =   
                    DataGridView.EditingControl as CheckedListBoxEditingControl;   
                InitializeCheckedListBox(ctl,(System.Collections.ICollection)this.FormattedValue);   
            }   
            private void InitializeCheckedListBox(CheckedListBox ctrl, System.Collections.ICollection value)   
            {   
                ctrl.Items.Clear();               
                foreach(object obj in value)   
                {   
                    ctrl.Items.Add(obj.ToString());   
                }   
                ctrl.Tag = this.Value;   
            }   
            public override Type EditType   
            {   
                get   
                {                  
                    return typeof(CheckedListBoxEditingControl);   
                }   
            }   
            protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)   
            {   
                if (value == null)   
                {   
                    return new List<object>();   
                }   
                return base.GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context);   
            }   
            public override Type FormattedValueType   
            {   
                get   
                {   
                    return typeof(System.Collections.ICollection);   
                }   
            }   
            public override Type ValueType   
            {   
                get   
                {                  
                    return typeof(System.Collections.ICollection);   
                }   
            }   
            private CheckedListBox internalControl;   
     
            protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)   
            {   
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);   
                graphics.FillRectangle(new SolidBrush(cellStyle.BackColor), cellBounds);   
     
                if (internalControl == null)   
                {   
                    internalControl = new CheckedListBox();                   
                }   
                internalControl.Items.Clear();   
                ICollection collection = value as ICollection;   
                if (collection != null)   
                {   
                    foreach (object obj in collection)   
                    {   
                        internalControl.Items.Add(obj);   
                    }   
                    Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height);   
                    internalControl.DrawToBitmap(bmp,new Rectangle(0,0,bmp.Width,bmp.Height));   
                    graphics.DrawImage(bmp,cellBounds,new Rectangle(0,0,bmp.Width,bmp.Height),GraphicsUnit.Pixel);                   
                }       
            }   
            protected override void OnClick(DataGridViewCellEventArgs e)   
            {   
                this.DataGridView.BeginEdit(false);   
                base.OnClick(e);   
            }   
        }   
     
        class CheckedListBoxEditingControl : CheckedListBox, IDataGridViewEditingControl   
        {   
            DataGridView dataGridView;   
            private bool valueChanged = false;   
            int rowIndex;   
     
            public CheckedListBoxEditingControl()   
            {   
     
            }   
     
            // Implements the IDataGridViewEditingControl.EditingControlFormattedValue    
            // property.   
            public object EditingControlFormattedValue   
            {   
                get   
                {   
                    return this.Tag;   
                }   
                set   
                {   
                  //  this.Tag = value;   
                }   
            }   
     
            // Implements the    
            // IDataGridViewEditingControl.GetEditingControlFormattedValue method.   
            public object GetEditingControlFormattedValue(   
                DataGridViewDataErrorContexts context)   
            {   
                return EditingControlFormattedValue;   
            }   
     
            // Implements the    
            // IDataGridViewEditingControl.ApplyCellStyleToEditingControl method.   
            public void ApplyCellStyleToEditingControl(   
                DataGridViewCellStyle dataGridViewCellStyle)   
            {   
                this.Font = dataGridViewCellStyle.Font;   
                this.ForeColor = dataGridViewCellStyle.ForeColor;   
                this.BackColor = dataGridViewCellStyle.BackColor;   
            }   
     
            // Implements the IDataGridViewEditingControl.EditingControlRowIndex    
            // property.   
            public int EditingControlRowIndex   
            {   
                get   
                {   
                    return rowIndex;   
                }   
                set   
                {   
                    rowIndex = value;   
                }   
            }   
     
            // Implements the IDataGridViewEditingControl.EditingControlWantsInputKey    
            // method.   
            public bool EditingControlWantsInputKey(   
                Keys key, bool dataGridViewWantsInputKey)   
            {   
                // Let the DateTimePicker handle the keys listed.   
                switch (key & Keys.KeyCode)   
                {   
                    case Keys.Left:   
                    case Keys.Up:   
                    case Keys.Down:   
                    case Keys.Right:   
                    case Keys.Home:   
                    case Keys.End:   
                    case Keys.PageDown:   
                    case Keys.PageUp:   
                        return true;   
                    default:   
                        return !dataGridViewWantsInputKey;   
                }   
            }   
     
            // Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit    
            // method.   
            public void PrepareEditingControlForEdit(bool selectAll)   
            {   
                // No preparation needs to be done.   
            }   
     
            // Implements the IDataGridViewEditingControl   
            // .RepositionEditingControlOnValueChange property.   
            public bool RepositionEditingControlOnValueChange   
            {   
                get   
                {   
                    return false;   
                }   
            }   
     
            // Implements the IDataGridViewEditingControl   
            // .EditingControlDataGridView property.   
            public DataGridView EditingControlDataGridView   
            {   
                get   
                {   
                    return dataGridView;   
                }   
                set   
                {   
                    dataGridView = value;   
                }   
            }   
     
            // Implements the IDataGridViewEditingControl   
            // .EditingControlValueChanged property.   
            public bool EditingControlValueChanged   
            {   
                get   
                {   
                    return valueChanged;   
                }   
                set   
                {   
                    valueChanged = value;   
                }   
            }   
     
            // Implements the IDataGridViewEditingControl   
            // .EditingPanelCursor property.   
            public Cursor EditingPanelCursor   
            {   
                get   
                {   
                    return base.Cursor;   
                }   
            }           
        }
    }
     
    // Le Form d'utilisation  avec un simple DataGridView
    //
    // utilisation avec un datatable auxiliaire compose de 2
    // champs:
    // simple => "NomChamp" 
    // complexe => "ListeValeur" (List(Of String)
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
     
    namespace DataGridViewListBoxCSharp
    {
        public partial class Form1 : Form
        {
             //les valeurs du tableau row sont envoyes dans le DataTable
            DataTable dt;
     
            public Form1()
            {
                InitializeComponent();
                this.Text = "Example DataGridView CheckedListBoxColumn ";
            }
     
            private void DataGridViewDT_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
     
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                // DATATABLE
                //  Creation des 2 champs
                dt =new DataTable();
                dt.TableName = "dt";
                dt.Columns.Add("NomChamp", typeof(String));
                dt.Columns.Add("ListeValeur", typeof(List<String>));
     
                //Remplir le champ complexe "ListeValeur"
                int nbValeur= 4;
                List<String> simpleListe  = new List<String>();
                for (int j=0; j < nbValeur; j++)
                {
                    simpleListe.Add("Valeur" + (j + 1).ToString());
     
                }
                //Remplit le datatable avec les 2 champs simple et complexe
     
                DataRow dr= dt.NewRow();
                for (int i=0; i < 10; i++)
                {
                    dr[0] = "NomChamp" + (i + 1).ToString();
                    dr[1] = simpleListe;
                    dt.Rows.Add(dr);
                    dr = dt.NewRow();
                }
     
                //  DataGridView
                // Ajouter notre colonne CheckedListBoxColumn(visible dans Designer 
                // si la classe CheckedListBoxColumn est dans le meme projet)
     
                CheckedListBoxColumn col= new CheckedListBoxColumn();
                col.HeaderText = "Liste des Valeurs";
                this.DataGridViewDT.Columns.Add(col);
     
                // Binder la colonne au champ "ListeValeur" de la DataTable
                this.DataGridViewDT.Columns[0].DataPropertyName = "ListeValeur";
     
                //Binder le DataGridView à la DataTable
                this.DataGridViewDT.DataSource = dt;
     
            }
        }
    }
    Comme je fais plus du VB.Net que du CSharp voici -mutatis mutandis- le meme code cette fois du meme CheckedListBoxColumn et de son cousin ListBoxColumn (ancetre commun ControList)

    code vb.net du CheckedListBoxColumn :

    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
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
     
    'La classe CheckedListBoxColumn
     
    'les memes considerations d'implementations que celles du ListBox s'appliquent 
    'au CheckListBox car  Rappel :
    'ListBox & CheckListBox heritent tous de l'ancetre commun 
    'ListControl ce qui explique une implementation similaire
     
    Public Class CheckedListBoxColumn
        Inherits DataGridViewColumn
     
        Public Sub New()
            MyBase.new(New CheckedListBoxCell)
     
        End Sub
        Public Overrides Property CellTemplate() As System.Windows.Forms.DataGridViewCell
            Get
                Return MyBase.CellTemplate
            End Get
            Set(ByVal value As System.Windows.Forms.DataGridViewCell)
                If (value IsNot Nothing And Not value.GetType().IsAssignableFrom(GetType(CheckedListBoxCell))) Then
     
                    Throw New InvalidCastException("Must be a CheckedListBoxCell")
                End If
                MyBase.CellTemplate = value
            End Set
        End Property
    End Class
    Public Class CheckedListBoxCell
        Inherits DataGridViewCell
     
        Public Sub New()
            MyBase.New()
        End Sub
        Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
     
            'Set the value of the editing control to the current cell value.   
            MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
     
            Dim ctl As CheckedListBoxEditingControl = _
                CType(DataGridView.EditingControl, CheckedListBoxEditingControl)
            InitializeCheckedListBox(ctl, CType(Me.FormattedValue, ICollection))
     
        End Sub
        Private Sub InitializeCheckedListBox(ByVal ctrl As CheckedListBox, ByVal value As ICollection)
            ctrl.Items.Clear()
            For Each obj As Object In value
                ctrl.Items.Add(obj.ToString())
            Next
            ctrl.Tag = Me.Value
        End Sub
        Public Overrides ReadOnly Property EditType() As System.Type
            Get
                'Return MyBase.EditType
                Return GetType(CheckedListBoxEditingControl)
            End Get
        End Property
     
        Protected Overrides Function GetFormattedValue(ByVal value As Object, ByVal rowIndex As Integer, ByRef cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal valueTypeConverter As System.ComponentModel.TypeConverter, ByVal formattedValueTypeConverter As System.ComponentModel.TypeConverter, ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object
            If (value Is Nothing) Then
                Return New List(Of Object)
            End If
            Return MyBase.GetFormattedValue(value, rowIndex, cellStyle, valueTypeConverter, formattedValueTypeConverter, context)
        End Function
        Public Overrides ReadOnly Property FormattedValueType() As System.Type
            Get
                'Return MyBase.FormattedValueType
                Return GetType(ICollection)
            End Get
        End Property
        Public Overrides Property ValueType() As System.Type
            Get
                'Return MyBase.ValueType
                Return GetType(ICollection)
            End Get
            Set(ByVal value As System.Type)
            End Set
        End Property
     
        'In order to display CheckedListBox in a DataGridView cell, 
        'you need to paint the cell by yourself
        Private internalControl As CheckedListBox
     
        Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal cellState As System.Windows.Forms.DataGridViewElementStates, ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
            MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
            graphics.FillRectangle(New SolidBrush(cellStyle.BackColor), cellBounds)
     
            If (internalControl Is Nothing) Then
                internalControl = New CheckedListBox()
            End If
            internalControl.Items.Clear()
            Dim collection As ICollection = CType(value, ICollection)
     
            If (collection IsNot Nothing) Then
                For Each obj As Object In collection
                    internalControl.Items.Add(obj)
                Next
                Dim bmp As Bitmap = New Bitmap(cellBounds.Width, cellBounds.Height)
                internalControl.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
                graphics.DrawImage(bmp, cellBounds, New Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel)
     
            End If
     
        End Sub
        Protected Overrides Sub OnClick(ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
            Me.DataGridView.BeginEdit(False)
            MyBase.OnClick(e)
        End Sub
    End Class
    Public Class CheckedListBoxEditingControl
        Inherits CheckedListBox
        Implements IDataGridViewEditingControl
     
        Private dataGridView As DataGridView
        Private valueChanged As Boolean = False
        Private rowIndex As Integer
        Public Sub New()
        End Sub
        'Implements the  IDataGridViewEditingControl.ApplyCellStyleToEditingControl 
        'method.   
        Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle) Implements System.Windows.Forms.IDataGridViewEditingControl.ApplyCellStyleToEditingControl
            Me.Font = dataGridViewCellStyle.Font
            Me.ForeColor = dataGridViewCellStyle.ForeColor
            Me.BackColor = dataGridViewCellStyle.BackColor
        End Sub
        'Implements the IDataGridViewEditingControl.EditingControlDataGridView 
        'property.
        Public Property EditingControlDataGridView() As System.Windows.Forms.DataGridView Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlDataGridView
            Get
                Return dataGridView
            End Get
            Set(ByVal value As System.Windows.Forms.DataGridView)
                dataGridView = value
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlFormattedValue    
        ' property.   
     
        Public Property EditingControlFormattedValue() As Object Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlFormattedValue
            Get
                Return Me.Tag
            End Get
            Set(ByVal value As Object)
                ' Me.Tag = value;   
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlRowIndex    
        'property.   
        Public Property EditingControlRowIndex() As Integer Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlRowIndex
            Get
                Return rowIndex
            End Get
            Set(ByVal value As Integer)
                rowIndex = value
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlValueChanged 
        'property
        Public Property EditingControlValueChanged() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlValueChanged
            Get
                Return valueChanged
            End Get
            Set(ByVal value As Boolean)
                valueChanged = value
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlWantsInputKey    
        'method. 
        Public Function EditingControlWantsInputKey(ByVal keyData As System.Windows.Forms.Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlWantsInputKey
            'Let the DateTimePicker handle the keys listed.   
            Select Case keyData And Keys.KeyCode
                Case Keys.Left, Keys.Up, Keys.Down, _
                Keys.Right, Keys.Home, Keys.End, _
                Keys.PageDown, Keys.PageUp
                    Return True
                Case Else
                    Return Not dataGridViewWantsInputKey
            End Select
        End Function
        'Implements the IDataGridViewEditingControl   
        '.EditingPanelCursor property. 
        Public ReadOnly Property EditingPanelCursor() As System.Windows.Forms.Cursor Implements System.Windows.Forms.IDataGridViewEditingControl.EditingPanelCursor
            Get
                Return MyBase.Cursor
            End Get
        End Property
        'Implements the IDataGridViewEditingControl.GetEditingControlFormattedValue 
        'method.   
        Public Function GetEditingControlFormattedValue(ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object Implements System.Windows.Forms.IDataGridViewEditingControl.GetEditingControlFormattedValue
            Return EditingControlFormattedValue
        End Function
        ' Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit    
        'method. 
        Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements System.Windows.Forms.IDataGridViewEditingControl.PrepareEditingControlForEdit
            'No preparation needs to be done. 
        End Sub
        'Implements the IDataGridViewEditingControl.RepositionEditingControlOnValueChange 
        'property. 
        Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.RepositionEditingControlOnValueChange
            Get
                Return False
            End Get
        End Property
    End Class
     
    ' Le Form d'utilisation  avec un simple DataGridView
    '
    'utilisation avec un datatable auxiliaire compose de 2
    'champs:
    'simple => "NomChamp" 
    'complexe => "ListeValeur" (List(Of String)
    Public Class frmCheckedListBoxColum
        'les valeurs du tableau row sont envoyes dans le DataTable
        Dim dt As DataTable
        Public Sub New()
     
            ' Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            Me.Text = "DataGridView CheckedListBoxColumn "
        End Sub
     
     
        Private Sub frmCheckedListBoxColum_Load(ByVal sender As Object, ByVal e As EventArgs) _
            Handles Me.Load
     
            '1/DATATABLE
            'Creation des 2 champs
            dt = New DataTable
            dt.TableName = "dt"
            dt.Columns.Add("NomChamp", GetType(String))
            dt.Columns.Add("ListeValeur", GetType(List(Of String)))
     
            'Remplir le champ complexe "ListeValeur"
            Dim nbValeur As Integer = 4
            Dim simpleListe As List(Of String) = New List(Of String)
            For j As Integer = 0 To nbValeur
                simpleListe.Add("Valeur" & (j + 1).ToString)
            Next
            'Remplit le datatable avec les 2 champs simple et complexe
            Dim dr As DataRow = dt.NewRow
            For i As Integer = 0 To 9
                dr(0) = "NomChamp" & (i + 1).ToString
                dr(1) = simpleListe
                dt.Rows.Add(dr)
                dr = dt.NewRow
            Next
     
            '2/DataGridView
            'Ajoute notre colonne CheckedListBoxColumn(visible dans Designer 
            'si la classe CheckedListBoxColumn est dans le meme projet)
            Dim col As CheckedListBoxColumn = New CheckedListBoxColumn
            col.HeaderText = "Liste des Valeurs"
            Me.DataGridViewDT.Columns.Add(col)
     
            'binder la colonne au champ "ListeValeur" de la DataTable
            Me.DataGridViewDT.Columns(0).DataPropertyName = "ListeValeur"
     
            'Binder le DataGridView à la DataTable
            Me.DataGridViewDT.DataSource = dt
     
     
        End Sub
    End Class
    code vb.net du ListBoxColumn :
    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
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
     
    'La classe ListBoxColumn
     
    Imports System.ComponentModel
    Imports System.Windows.Forms.ListBox
    Imports System.Drawing.Design
     
    Public Class ListBoxColumn
        Inherits DataGridViewColumn
     
        Public Sub New()
            MyBase.new(New ListBoxCell)
     
        End Sub
        Public Overrides Property CellTemplate() As System.Windows.Forms.DataGridViewCell
            Get
                Return MyBase.CellTemplate
            End Get
            Set(ByVal value As System.Windows.Forms.DataGridViewCell)
                If (value IsNot Nothing And Not value.GetType().IsAssignableFrom(GetType(ListBoxCell))) Then
     
                    Throw New InvalidCastException("Must be a ListBoxCell")
                End If
                MyBase.CellTemplate = value
            End Set
        End Property
     
    End Class
     
    Public Class ListBoxCell
        Inherits DataGridViewCell
        Public Sub New()
            MyBase.New()
        End Sub
        Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
     
            MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
     
            'Set the value of the editing control to the current cell value.   
            Dim ctl As ListBoxEditingControl = _
                CType(DataGridView.EditingControl, ListBoxEditingControl)
            InitializeListBox(ctl, CType(Me.FormattedValue, ICollection))
     
        End Sub
        Private Sub InitializeListBox(ByVal ctrl As ListBox, ByVal value As ICollection)
            ctrl.Items.Clear()
            For Each obj As Object In value
                ctrl.Items.Add(obj.ToString())
            Next
            ctrl.Tag = Me.Value
        End Sub
        Public Overrides ReadOnly Property EditType() As System.Type
            Get
                'Return MyBase.EditType
                Return GetType(TestListBoxEditingControl)
            End Get
        End Property
     
        Protected Overrides Function GetFormattedValue(ByVal value As Object, ByVal rowIndex As Integer, ByRef cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal valueTypeConverter As System.ComponentModel.TypeConverter, ByVal formattedValueTypeConverter As System.ComponentModel.TypeConverter, ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object
            If (value Is Nothing) Then
                Return New List(Of Object)
            End If
            Return MyBase.GetFormattedValue(value, rowIndex, cellStyle, valueTypeConverter, formattedValueTypeConverter, context)
        End Function
        Public Overrides ReadOnly Property FormattedValueType() As System.Type
            Get
                'Return MyBase.FormattedValueType
                Return GetType(ICollection)
            End Get
        End Property
        Public Overrides Property ValueType() As System.Type
            Get
                'Return MyBase.ValueType
                Return GetType(ICollection)
            End Get
            Set(ByVal value As System.Type)
            End Set
        End Property
        'In order to display ListBox in a DataGridView cell, 
        'you need to paint the cell by yourself
        Private internalControl As ListBox
     
        Protected Overrides Sub Paint(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal cellState As System.Windows.Forms.DataGridViewElementStates, ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
            MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
            graphics.FillRectangle(New SolidBrush(cellStyle.BackColor), cellBounds)
     
            If (internalControl Is Nothing) Then
                internalControl = New ListBox()
            End If
            internalControl.Items.Clear()
            Dim collection As ICollection = CType(value, ICollection)
     
            If (collection IsNot Nothing) Then
                For Each obj As Object In collection
                    internalControl.Items.Add(obj)
                Next
                Dim bmp As Bitmap = New Bitmap(cellBounds.Width, cellBounds.Height)
                internalControl.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
                graphics.DrawImage(bmp, cellBounds, New Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel)
     
            End If
     
        End Sub
        Protected Overrides Sub OnClick(ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
            Me.DataGridView.BeginEdit(False)
            MyBase.OnClick(e)
        End Sub
    End Class
    Public Class ListBoxEditingControl
        Inherits ListBox
        Implements IDataGridViewEditingControl
     
        Private dataGridView As DataGridView
        Private valueChanged As Boolean = False
        Private rowIndex As Integer
        Public Sub New()
        End Sub
        'Implements the  IDataGridViewEditingControl.ApplyCellStyleToEditingControl 
        'method.   
        Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle) Implements System.Windows.Forms.IDataGridViewEditingControl.ApplyCellStyleToEditingControl
            Me.Font = dataGridViewCellStyle.Font
            Me.ForeColor = dataGridViewCellStyle.ForeColor
            Me.BackColor = dataGridViewCellStyle.BackColor
        End Sub
        'Implements the IDataGridViewEditingControl.EditingControlDataGridView 
        'property.
        Public Property EditingControlDataGridView() As System.Windows.Forms.DataGridView Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlDataGridView
            Get
                Return dataGridView
            End Get
            Set(ByVal value As System.Windows.Forms.DataGridView)
                dataGridView = value
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlFormattedValue    
        ' property.   
     
        Public Property EditingControlFormattedValue() As Object Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlFormattedValue
            Get
                Return Me.Tag
            End Get
            Set(ByVal value As Object)
                ' Me.Tag = value;   
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlRowIndex    
        'property.   
        Public Property EditingControlRowIndex() As Integer Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlRowIndex
            Get
                Return rowIndex
            End Get
            Set(ByVal value As Integer)
                rowIndex = value
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlValueChanged 
        'property
        Public Property EditingControlValueChanged() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlValueChanged
            Get
                Return valueChanged
            End Get
            Set(ByVal value As Boolean)
                valueChanged = value
            End Set
        End Property
        'Implements the IDataGridViewEditingControl.EditingControlWantsInputKey    
        'method. 
        Public Function EditingControlWantsInputKey(ByVal keyData As System.Windows.Forms.Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlWantsInputKey
            'Let the DateTimePicker handle the keys listed.   
            Select Case keyData And Keys.KeyCode
                Case Keys.Left, Keys.Up, Keys.Down, _
                Keys.Right, Keys.Home, Keys.End, _
                Keys.PageDown, Keys.PageUp
                    Return True
                Case Else
                    Return Not dataGridViewWantsInputKey
            End Select
        End Function
        'Implements the IDataGridViewEditingControl   
        '.EditingPanelCursor property. 
        Public ReadOnly Property EditingPanelCursor() As System.Windows.Forms.Cursor Implements System.Windows.Forms.IDataGridViewEditingControl.EditingPanelCursor
            Get
                Return MyBase.Cursor
            End Get
        End Property
        'Implements the IDataGridViewEditingControl.GetEditingControlFormattedValue 
        'method.   
        Public Function GetEditingControlFormattedValue(ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object Implements System.Windows.Forms.IDataGridViewEditingControl.GetEditingControlFormattedValue
            Return EditingControlFormattedValue
        End Function
        ' Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit    
        'method. 
        Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements System.Windows.Forms.IDataGridViewEditingControl.PrepareEditingControlForEdit
            'No preparation needs to be done. 
        End Sub
        'Implements the IDataGridViewEditingControl.RepositionEditingControlOnValueChange 
        'property. 
        Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.RepositionEditingControlOnValueChange
            Get
                Return False
            End Get
        End Property
     
     
    End Class
     
    ' Le Form d'utilisation  avec un simple DataGridView et un TextBox en plus.
    ' et gestion de l'evenement DataGridView_EditingControlShowing et
    ' interaction avec notre ListBoxColumn
    '-------------------------------------------------------------
    '
    'utilisation avec un datatable auxiliaire compose de 2
    'champs:
    'simple => "NomChamp" 
    'complexe => "ListeValeur" (List(Of String) 
    Public Class frmListBoxColum
        'les valeurs du tableau row sont envoyes dans le DataTable
        Dim dt As DataTable
        Public Sub New()
     
            ' Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            Me.Text = "DataGridView ListBoxColumn"
        End Sub
     
     
        Private Sub Form2_Load(ByVal sender As Object, ByVal e As EventArgs) _
            Handles Me.Load
     
            '1/DATATABLE
            'Creation des 2 champs
            dt = New DataTable
            dt.TableName = "dt"
            dt.Columns.Add("NomChamp", GetType(String))
            dt.Columns.Add("ListeValeur", GetType(List(Of String)))
     
            'Remplir le champ complexe "ListeValeur"
            Dim nbValeur As Integer = 4
            Dim simpleListe As List(Of String) = New List(Of String)
            For j As Integer = 0 To nbValeur
                simpleListe.Add("Valeur" & (j + 1).ToString)
            Next
            'Remplit le datatable avec les 2 champs simple et complexe
            Dim dr As DataRow = dt.NewRow
            For i As Integer = 0 To 9
                dr(0) = "NomChamp" & (i + 1).ToString
                dr(1) = simpleListe
                dt.Rows.Add(dr)
                dr = dt.NewRow
            Next
     
            '2/DataGridView
            'Ajoute notre colonne ListBoxColumn(visible dans Designer 
            'si la classe ListBoxColumn est dans le meme projet)
            Dim col As ListBoxColumn = New ListBoxColumn
            col.HeaderText = "Liste des Valeurs"
            Me.DataGridViewDT.Columns.Add(col)
     
            'binder la colonne au champ "ListeValeur" de la DataTable
            Me.DataGridViewDT.Columns(0).DataPropertyName = "ListeValeur"
     
            'Binder le DataGridView à la DataTable
            Me.DataGridViewDT.DataSource = dt
        End Sub
        'L'exemple est calque sur  le code MSDN (cite-apres).Il montre 
        'comment utiliser un gestionnaire d'événements DataGridView.EditingControlShowing
        'pour ajouter un gestionnaire pour un événement 
        'de la classe encapsule ListBoxEditingControl. 
        'Dans l'exemple, le contrôle d'édition est casté en un ListBox pour gérer
        'l'événement ListBox.SelectedIndexChanged.
        '(voir exemple MSDN ComboBox )
        Private Sub DataGridViewDT_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridViewDT.EditingControlShowing
            Dim objListBox As ListBox = CType(e.Control, ListBox)
            If (objListBox IsNot Nothing) Then
     
                ' Remove an existing event-handler, if present, to avoid 
                ' adding multiple handlers when the editing control is reused.
                RemoveHandler objListBox.SelectedIndexChanged, _
                    New EventHandler(AddressOf ListBox_SelectedIndexChanged)
     
                ' Add the event handler. 
                AddHandler objListBox.SelectedIndexChanged, _
                    New EventHandler(AddressOf ListBox_SelectedIndexChanged)
     
            End If
     
     
        End Sub
        'handler ListBox_SelectedIndexChanged
        Private Sub ListBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
     
            Dim objListBox1 As ListBox = CType(sender, ListBox)
            ' Get the currently selected item in the ListBoxColumn.
            Dim curItem As String = objListBox1.SelectedItem.ToString
            Dim index As Integer = objListBox1.SelectedIndex
            If index = -1 Then
                MessageBox.Show("Item is not available in ListBoxColumn")
            Else
                Me.TextBox1.Text = curItem
                Me.TextBox1.ForeColor = Drawing.Color.Red
            End If
        End Sub
    End Class
    Sur ce dernier bout de code du ListBox j'ai repris un exemple MSDN d'interaction avec un ComboxColumn grace à l'evenement DataGridView_EditingControlShowing du DataGridViex qui est general que j'ai applique au ListBoxColumn(meme principe pour le CheckedListColumn).

    Car il est valable pour tous les controls dont l'ancetre est ControlList en l'occurrence ComboxColumn ,ListBoxColumn ,CheckedListColumn ....
    Par ailleurs il y a lieu de noter un autre point important :la classe EditingControl est directement acccessible dans DataGridView(prop).

    Tu peux toujours reprendre le code vb.net de l'evenement DataGridView_EditingControlShowing en csharp .
    En esperant que cela puisse aider ....
    bon code................

  7. #7
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2010
    Messages
    479
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

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

    Informations forums :
    Inscription : Août 2010
    Messages : 479
    Points : 762
    Points
    762
    Par défaut
    Bonjour,
    ce n'est pas moi qui ait posté mais alexxxx69.
    Et étant donné qu'il ne veut pas une listBox à choix multiple (checkedlistbox) une simple DataGridViewComboBoxCell suffit. Unitile donc de lui compliquer autant sa Form.

    Par contre merci pour ce code qui me sera surement utile un jour

  8. #8
    Membre habitué
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2009
    Messages
    236
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 236
    Points : 133
    Points
    133
    Par défaut
    Merci lead8209, c'est exactement ce que je voulais. Y'a tellement de propriétés et possibilités entre VB6 et .NET que j'étais un peu perdu
    La Solution AGILE de Cartographie et d'Urbanisation des Systèmes d'Information éditée et développée par la société AB+ SOFTWARE
    https://www.abplussoftware.fr

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 01/07/2015, 18h35
  2. Réponses: 0
    Dernier message: 14/01/2015, 16h18
  3. Réponses: 5
    Dernier message: 05/06/2008, 00h43
  4. [XSLT]tableau double entrée avec cellule manquante
    Par nferay dans le forum XSL/XSLT/XPATH
    Réponses: 9
    Dernier message: 08/03/2005, 16h07
  5. [XSL-FO] Table avec cellule vide
    Par JustAGphy dans le forum XSL/XSLT/XPATH
    Réponses: 6
    Dernier message: 12/05/2004, 15h11

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