I'm adding a DataGridViewComboBoxColumn
to a DataGridView
during the form's Load
event handler and setting the DataSource of each DataGridViewComboBoxCell
in the columns. However, once the form is shown, the DataSource of each DataGridViewComboBoxCell
has been set to null
. Here is the code I use to populate the column and it's cells:
DataGridViewComboBoxColumn comboCol;
comboCol = new DataGridViewComboBoxColumn();
comboCol.Name = "ComboCol";
comboCol.HeaderText = "Combo Column";
comboCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
this.dgv.Columns.Add(comboCol);
for (int i = 0; i < dgv.Rows.Count; i++)
{
// This datatable is actually populated here!
DataTable myData = PopulatedDataTable(dgv.Rows[i].Cells["info"].Value);
DataGridViewComboBoxCell DCC = new DataGridViewComboBoxCell();
DCC = (DataGridViewComboBoxCell)dgv.Rows[i].Cells["CombolCol"];
DCC.DataSource = myData;
DCC.DisplayMember = "Association"; // Association is a column in myData
DCC.ValueMember = "Association";
}
dgv.Columns["association"].Visible = false;
This code does exactly what is expected if I put it in a button that I click AFTER the form has loaded, but when executed during form load the DataSource is cleared. Any suggestions?