I want to bind the value of cells in one column to another column in a datagridview. The 1st column is Team and the other is Assignment. I want to set the the selected value (Assignment.Value; teamComboBox.ValueMember ) = (Team.Value; row.Cells.Item(6)) after the dgv is loaded.
This is what I have so far:
Dim conn As New SqlConnection(My.Resources.FCLRptConn)
Dim cmd As New SqlCommand("spFCLLUVTeamAssignment", conn)
Dim da As New SqlDataAdapter(cmd)
Dim TeamAssign As New DataTable
da.Fill(TeamAssign)
With FCLTeam
.DataPropertyName = "FCLTeam"
.Name = "FCLTeam"
.DataSource = TeamAssign
.DisplayMember = "FCLTeamName"
.ValueMember = "FCLTeamID"
.AutoSizeMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
.DisplayIndex = 6
End With
I now have 2 columns appearing in the DGV. One is from the dataset and the other is the datagridcomboboxcolumn that I added.
How would I show only the datagridcomboboxcolumn ?
Unless there are very specific reasons not to, you can bind the two columns to the same field value.
If that doesn't work for you please add additional details on your requirements.
EDIT:
You must use DataGridViewComboBoxColumn
and set its ValueMember
and DisplayMember
on the appropriate field names. ValueMember
usually is the key field of the data source used to populate the combobox.
Once this is set correctly you won't need to loop through your grid rows. Binding will take care of matching the appropriate combobox element.