I have seen many solutions for this involving data binding, but I do not have a data source. In this case, the combined cell applies only to 1 row (other rows do not have a DataGridViewComboBoxCell).
I set DataGridViewComboCell as follows:
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox; cell.Items.AddRange(items.ToArray()); // items is List<string>
And I dynamically re-populate it later as follows:
_cell.Items.Clear(); _cell.Items.AddRange(this.Data.ResponseOptions.Select( d => d.Description).ToArray());
But then I get this nasty dialogue that reads:
The following exception occurred in the DataGridView: System.ArgumentException: DataGridViewComboBoxCell is not valid. To replace this default dialog box, handle the DataError event.
This does not help, by the way, to say that it is not "valid." Can I send an email to MS saying that Windows Forms is not valid?
I tried to capture the property of the cell elements and add rows using foreach () with a call to Add (). I am still getting a dialogue.
I also tried to blow away the whole cell every time I want to update it and recreate a new DataGridViewComboCell from scratch. I am still getting a dialogue.
I also tried manually overwriting the value of the columns (successfully when I don't have this problem). However, this did not fix it.
It seems to me that this dialog appears when I try to multiply elements in a combo cell.
Now I just destroyed the DataError method.
Any suggestions?