0

How can I add items to an existing combobox cell in a new datagridview row?

When the user wants to add a new row, this combobox must to have its values populated, so that the user can select one.

dataGridViewCellphones.AutoGenerateColumns = false;

DataGridViewRow row = (DataGridViewRow)dataGridViewCellphones.Rows[0].Clone();

DataGridViewComboBoxColumn countries= new  
DataGridViewComboBoxColumn();

countries.DataSource = tempCountryList;
countries.DisplayMember = "EnglishName";
countries.ValueMember = "CountriesID";

row.Cells[1].Value = countries;
dataGridViewCellphones.Rows.Add(row);
thomasb
  • 5,816
  • 10
  • 57
  • 92
motevalizadeh
  • 5,244
  • 14
  • 61
  • 108
  • Do you mean that you want to enter in the cell values not belonging to the items of the DataGridViewComboBoxColumn? In other words, shall the combobox behave in a DropDown mode rather than in DropDowwnList that don't allow to enter values not belonging to the list? – Graffito Jun 20 '15 at 20:11
  • just want to fill a Combo box on my added rows like default value – motevalizadeh Jun 20 '15 at 20:26
  • Same as standard columns, i.e. row.Cells["MyColumnName"].Value = MyDefaultValue. – Graffito Jun 20 '15 at 20:33
  • i have got this error: dataGridViewComboBoxCellphone value is not valid – motevalizadeh Jun 20 '15 at 20:36
  • add default value to the DataSource of DataGridViewComboBoxColumn. In your case add value to `tempCountryList` – Fabio Jun 20 '15 at 20:37
  • Are you sure that the default value type corresponds to the Combobox column and that the default value belongs to the datasource items? – Graffito Jun 20 '15 at 20:44
  • yes, i'm sure about it – motevalizadeh Jun 20 '15 at 20:58
  • 1
    `row.Cells[1].Value = countries;` Does this even compile? I think it should be `row.Cells[1]= countries;` – TaW Jun 21 '15 at 07:58
  • possible duplicate of [Adding ComboBoxes to a DataGridView programatically](http://stackoverflow.com/questions/18225097/adding-comboboxes-to-a-datagridview-programatically) – PiotrWolkowski Jun 21 '15 at 16:19

0 Answers0