根据某些条件在运行时更改datagridview的单元格类型。 [英] Change cell type of datagridview at runtime based on some condition.

查看:53
本文介绍了根据某些条件在运行时更改datagridview的单元格类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有7列数据集填充的datagridview,如果数据库中的caste字段不为null,我需要在运行时将单元格类型从textboxcolumn更改为comboboxcolumn。

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





但即使数据库中的caste字段不为null,每行也会更改为textboxcolumn。请帮助我。



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

推荐答案

在初始查询中,您需要使用值所在的表子查询(连接)列。然后,它将自动解析,因为网格将理解该值是可用值的选择在子查询中使用的表中。您无法手动执行此操作,因为网格从数据源派生所有内容以确保完整性。



祝你好运!
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!


这篇关于根据某些条件在运行时更改datagridview的单元格类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆