如果datagridview列为空,则显示Null [英] Display Null if datagridview Column is empty

查看:641
本文介绍了如果datagridview列为空,则显示Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很少列单元格的DataGridView。我想要的只是检查空单元格并默认写入null。如果某些列没有填充。我想要提交的特定单元格的默认空文本



我试图创建这样的东西,但它不是工作,因为我不知道我怎么能进一步采取



I have a DataGridView with few column cells. all i want is to check an empty cells and write null by default. if some of the columns are not filled., i want a default null text to the specific cells that are committed

I tried to create something like this but it is not working as i don't know how i can take it further

if (Gridview_Output.Rows.Count > 0)
            {

                foreach (DataRow dr in oDataSet.Tables[0].Rows)
                {

                    string _Car = dr[1].ToString();
                    string _Dealer = dr[2].ToString();
                    string _Model = dr[4].ToString();

                    if (_Car.Length == 0)
                    {
                        _Car = "NULL";
                    }

                    if (_Dealer.Length == 0)
                    {
                        _Dealer = "NULL";
                    }

                    if (_Model.Length == 0)
                    {
                        _Model = "NULL";
                    }
                }

            }

推荐答案

参考:

DataGridViewCellStyle.NullValue Property [ ^ ]


这篇关于如果datagridview列为空,则显示Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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