我有一个数据网格视图。我的数据网格视图列的第3行是组合框,在第3列的每一行中我想要带有一些特定数据的组合框。所以在表单加载事件和数据网格视图单元格内容中单击我给出这样的代码。但是只有第一行数据网格视图的第3列填满,第2行第3列变空白。我的代码是这样的:
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
答案 0 :(得分:0)
检查此链接可以帮助您
最新代码
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