How to fill ComboBox in Datagridview in vb.net
I have added a combo box in a specific column in the grid and i have populated it. So when the grid is filled the combo box are also filled with predefined values.
1. Write the code at .vb page
Dim sql As Stringsql = "select * from color_mas"
Dim dt As DataTable
dt = DataTable(sql)
If dt.Rows.Count > 0 Then
'For j As Integer = 0 To dt.Rows.Count - 1
Dim col As New DataGridViewComboBoxColumn
col.DataPropertyName = "Color Name"
col.HeaderText = "Colorname"
col.Name = "Colorid"
col.DataSource = dt
col.DisplayMember = "Colorname"
col.ValueMember = "Colorid"
DataGridView1.Columns.Insert(0, col)
End If
No comments:
Post a Comment