Click here to Skip to main content
15,939,620 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have datagridview populated from dataset with 7 columns ,out of which last column "caste" I need to change cell type from textboxcolumn to comboboxcolumn at runtime if caste field in database is not null.
VB
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
                    
                Else
                    col_Caste.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton
                End If
            End If

        Next


But each row is changed to textboxcolumn even if caste field in database is not null.Please help me.
Posted

1 solution

In your initial query you need to subquery (join) the column Caste with the table the values are in. It will then automatically be solved because the grid will understand that the value is a choice from the possible values available in the table used in the subquery. You cannot do this by hand because the grid derives everything from the datasource for integrity.

Good luck!
 
Share this answer
 
Comments
Rachna0309 3-Jan-13 5:42am    
both tables are not linked so I cant join them.
E.F. Nijboer 3-Jan-13 8:40am    
You might consider joining them, or for now just add the join into your query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900