Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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.
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 2-Jan-13 21:58pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
Rachna0309 at 3-Jan-13 5:42am
   
both tables are not linked so I cant join them.
E.F. Nijboer at 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)

  Print Answers RSS
0 OriginalGriff 210
1 Richard MacCutchan 100
2 kbrandwijk 100
3 ProgramFOX 80
4 Mukesh Bhagat 65
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100