user3252014
user3252014

Reputation: 665

Not filling combo box data in all rows of data grid view in windows application

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

Answers (1)

pankeel
pankeel

Reputation: 1148

Check this link it can be help you

http://social.msdn.microsoft.com/Forums/en-US/09a07147-4423-4097-a3bd-e0d9d22b04a0/fill-datagridview-combobox-column?forum=winformsdatacontrols

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

Related Questions