I have databound datagridview with 10 columns.Out of which last column("caste"), I want it as comboboxcolumn filled with some values.Database table has caste as field name.Now if this field have some value,that corresponding record should show that value as default value selected in combobox column else combobox selected value should be null.I have tried the below code but its not working.
Is there any better option than this?
For Each row As DataGridViewRow In dgvUserDetails.Rows
sql = "Select caste from datafile where Part_No = " & dgvUserDetails.Item("Part_No", row.Index).Value & " and SLNOINPART = " & dgvUserDetails.Item("SLNOINPART", row.Index).Value & " and fullname = '" & dgvUserDetails.Item("Name", row.Index).Value & "'"
If rs.State = 1 Then rs.Close()
rs.Open(sql, MainCon, 1, 3)
If Not rs.EOF Then
gCaste_Id = rs.Fields(0).Value.ToString
If gCaste_Id.ToString <> "" Then
sql = "Select Description from Category where ID = " & gCaste_Id & ""
If rs.State = 1 Then rs.Close()
rs.Open(sql, MainCon, 1, 3)
If Not rs.EOF Then
gCaste = rs.Fields(0).Value
End If
dgvUserDetails.CurrentRow.Cells(10).Value = gCaste
col_Caste.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
col_Caste.DisplayMember = "Description"
Else
col_Caste.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton
End If
End If
Next
Is there any better option than this?