Home:ALL Converter>Filling DataGridView ComboBox programatically in unbound mode?

Filling DataGridView ComboBox programatically in unbound mode?

Ask Time:2014-12-26T17:20:44         Author:Amen Jlili

Json Formatter

The following code snippet (The question is here: http://www.vbdotnetforums.com/winforms-grids/10038-fill-datagridview-combobox-column.html) is for filling a combobox cell in a datagridview in unbound mode:

Dim dgvcc As DataGridViewComboBoxCell
dgvcc = DataGridView1.Rows(2).Cells(0)
dgvcc.Items.Add("comboitem1")
dgvcc.Items.Add("comboitem2")

I'm trying to do likewise but I can't help but notice that the casting operation is invalid and that's the exact error VB gives me.

I've tweaked the code a bit and tried it but still I get the same casting error:

Dim dgvcc As Windows.Forms.DataGridViewComboBoxCell
dgvcc = Window.DataGridView1.Rows(2).Cells(0)
dgvcc.Items.Add("comboitem1")
dgvcc.Items.Add("comboitem2")

Window is the name of the form in which the DataGridView1 objet is.

Can anyone please show me an easy method to fill a combobox in a datagridview in unbound mode. You can as well tell me why it did not work for me and why it is working for others?

Author:Amen Jlili,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27655152/filling-datagridview-combobox-programatically-in-unbound-mode
yy