0
Answer

datagridviewcombobox column

Ricardo Carvalho

Ricardo Carvalho

16y
4.4k
1
Hi.

I am having an issue with a dataGridView. (again). *sigh*. Basically I am trying to load the data in the DataGridView programmatically. However, the issue is that one of the colums is a ComboBox column. I am trying to get the data source of this column to load from an ArrayList of Strings.

This is the code that I am using:

string[] temp = GetTableNames();
            DataGridViewComboBoxCell dgvcelExcel = new DataGridViewComboBoxCell();
            try
            {
                for (int i = 0; i < temp.Length; i++)
                {
                    dgvcelExcel.DataSource = ColumNames; // ColumnNames is the arraylist in Q here.
                    dgvcelExcel.Value = i;
                    this.dgvMapping.Rows.Add(true, temp[i].ToString(), dgvcelExcel);
                }
                this.dgvMapping.Columns[0].DisplayIndex = 0;
                this.dgvMapping.Columns[1].DisplayIndex = 1;
                this.dgvMapping.Columns[2].DisplayIndex = 2;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

The error that it throws is :

the following exception occurred n the datagridview:
System.ArgumentException: DataGridViewComboBox value is not valid.
To replace his default dialog please hand the DataError event.

handling the DataError event doesn't really help my situation coz I wouldn't know what to do.

when I step through my code, there is no error what so ever. The error only pops up when the form is painting.

If there is any one that can help, please do.

Thanks
Ricardo