Question DataGridViewComboBoxColumn setting SelectedIndex

tim8w

Active member
Joined
Oct 26, 2010
Messages
38
Programming Experience
5-10
I have a DataGridViewComboBoxColumn that I allow the user to add new items to by typing in the ComboBox and hitting the 'Enter' key. That triggers CellValidating and I do the adding there by the following:

cmbColumn.Items.Add(e.FormattedValue)

All this works well, except that it leaves the DataGridViewComboBoxColumn blank. How can I set the DataGridViewComboBoxColumn to display the e.FormattedValue?
 
I finally figured it out. Here's what I had to do:

VB.NET:
Dim CBox As DataGridViewComboBoxCell = CType(dgvRecipe.Rows(e.RowIndex).Cells(e.ColumnIndex), DataGridViewComboBoxCell)

cmbColumnIngredient.Items.Add(e.FormattedValue)
CBox.Value = e.FormattedValue
 
Back
Top