Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridViewComboBoxColumn setting SelectedIndex

Status
Not open for further replies.

Tim8w

Programmer
Apr 8, 2003
44
0
0
US
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?
 
The assignment is very straight forward. The catch is that the data type being passed MUST be the exact same data type as the DataGridViewComboBoxColumn.ValueType.
Code:
e.Row.Cells(dcPayFlag.Index).Value = CByte(1)	 [COLOR=green]'Required to match data type of ValueType.[/color]

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
ousoonerjoe,
That looks like a plausible solution, unfortunately in CellValidating where I am adding the item, the e variable is of type:

System.Windows.Forms.DataGridViewCellValidatingEventArgs

which members do not include Row.

The member variables are:
Cancel
ColumnIndex
FormattedValue
RowIndex

 
I finally figured it out. Here's what I had to do:

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

cmbColumnIngredient.Items.Add(e.FormattedValue)
CBox.Value = e.FormattedValue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top