0 Replies - 5567 Views - Last Post: 05 January 2013 - 12:22 AM Rate Topic: -----

#1 Rachna0309  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-January 13

How to get a default value selected in combobox column?

Posted 05 January 2013 - 12:22 AM

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.

 
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?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1