Question Set Datagridviewcombobox value based on valuemember

esilva

New member
Joined
Aug 21, 2011
Messages
2
Programming Experience
1-3
Hi,
I have a datagridview with a combobox withing a modal form. The combobox shows a list of ingredients where the displaymember is the IngredientName and the valuemember is the IngredientID, and a user would select an ingredient in the combobox and the returning value would be the ID for that ingredient. My issue is that within this same datagridview, i'd like to prepopulate it with items already existing in the database. However i'd like to set the display value in the combobox using the id value from the database. So if "Pasta" was the ingredient name and 101 was the ID, i'd set the value as 101 and it display Pasta in the combobox.

Here's what i have so far:

VB.NET:
        For Each row As ListViewItem In listIngView.Items
            Dim i As Integer = dgvIngEdit.Rows.Add()
            dgvIngEdit.Rows(i).Cells(1).Value = row.Text
        Next

However doing this shows the ingredientid in the field instead of the ingredientname, but if i go in select the combobox (within the dgv) the ingredients will show, i can select a different ingredient and the ID is returned.

I'm stuck, please help.
 
You must not have bound your grid/column properly. Setting the Value of the cell is exactly what you should do. Check this out and make sure you're creating the column and bind in the same way.

Adding a ComboBox Column to a DataGridView
 
Back
Top