Friday, 23 August 2013

How should I load all the data from a column to a datagridview combobox?

How should I load all the data from a column to a datagridview combobox?

How can I make the codes work so that the datagridview combobox load 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

No comments:

Post a Comment