Reputation: 665
I have a data grid view. 3rd row of my data grid view column is combo box, in every row of 3rd column i want to come that combo box with some particular data. So in form load event and data grid view cell content click I given code like this. But in only 3rd column of first row of data grid view got filled, 2nd row 3rd column getting blank. My code like this:
If e.ColumnIndex = 3 Then
Dim dgvcc As DataGridViewComboBoxCell
Dim cmd As New SqlCommand(" select DName from Designation_tbl where deleted=0", con.connect)
dr = cmd.ExecuteReader
For i As Integer = 0 To DGVEmployee.Rows.Count - 1
dgvcc = DGVEmployee.Rows(i).Cells(3)
While dr.Read
dgvcc.Items.Add(dr("DName"))
End While
dr.Close()
con.disconnect()
Next
End If
Upvotes: 0
Views: 1022
Reputation: 1148
Check this link it can be help you
latest code
If e.ColumnIndex = 3 Then
Dim c As DataGridViewComboBoxColumn
Dim cmd2 As New SqlCommand("select Did,DName from Designation_tbl where deleted=0", con.connect)
cmd2.CommandType = CommandType.Text
Dim objdataadapter As New SqlDataAdapter(cmd2)
Dim results As New DataSet
objdataadapter.Fill(results, "DesignationMaster_tbl")
c = DGVEmployee.Columns(3)
c.DataSource = results.Tables("DesignationMaster_tbl")
c.ValueMember = "Did"
c.DisplayMember = "DName"
con.disconnect()
end if
Upvotes: 0