How can I make that the datagridview combobox loads with the items listed in the 'userid' column in my database? I want all the items to be listed on the datagridview combobox from the 'userid' column.
Here are the lines I've written so far:
Private Sub check()
cmd = New SqlCommand("Select UserID from info", con)
da = New SqlDataAdapter(cmd)
dt = New DataTable()
da.Fill(dt)
If dt.Rows.Count > 0 Then
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "UserID"
Dim dgvcolumn As New DataGridViewComboBoxColumn
With dgvcolumn
.Width = 150
.Items.Add(ComboBox1.Items)
.DataPropertyName = "UserID"
.HeaderText = "UserID"
End With
Else
End If
End Sub
Why not add an unbound column, type should be ComboBoxColumn. Then add a data source (named infobindingsource) that grabs the userid column from your info table and set the new column's data source to be the infobindingsource.
ilann