在WinForms中为datagridview中的单元格提供Null值 [英] Provide Null Value to a cell in datagridview in winforms

查看:82
本文介绍了在WinForms中为datagridview中的单元格提供Null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的Windows应用程序中有一个datagridview,该数据库现在从数据库获取日期值,我想将空值传递给列[1]中日期值为"01-Jan-1900"的那些单元格.请告诉我我该怎么做?

Hi all,

I have one datagridview in my windows application which gets date values from database now i want to pass null value to those cell in column[1] who have date value "01-Jan-1900". please tell me how can i do that ?

推荐答案

Nullable datetime column in .NET DataGrid with DateTimePicker[^] should give you some ideas.


请通过代码进行解释阻止如何绑定数据网格...?
Please explain by code block how to bind your data grid ... ?


我将以下代码放在rows的add代码事件的datagridview中,并且我工作了

i put below code at rowsAdd event of datagridview and i worked

string datetimevalue = "01/01/1900 12:00:00 AM";
            try
            {
                for (int i = 0; i < dgvRenewalHistory.Rows.Count; i++)
                {
                    if (dgvRenewalHistory.Rows[i].Cells["Renewal_On"].Value.ToString() == datetimevalue)
                    {
                        dgvRenewalHistory.Rows[i].Cells["Renewal_On"].Value = "";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


这篇关于在WinForms中为datagridview中的单元格提供Null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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