Click here to Skip to main content
12,756,303 members (35,127 online)

Change cell type of datagridview at runtime based on some condition.

Rachna0309 asked:

Open original thread
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
                    col_Caste.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton
                End If
            End If


But each row is changed to textboxcolumn even if caste field in database is not null.Please help me.
Tags: VB, VB.NET


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
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