如何在datagridview单元格中允许空值? [英] how to allow null values in datagridview cells?

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

问题描述

如何在datagridview单元格中允许空值?

i有3列是...

i输入第1列--->第1个单元格值然后输入错误将来了

这意味着2列 - >第一个单元格为空啊..... 2column - > 1at cell null values dot允许datagridview



如何在datagridview单元格中允许空值?

how to allow null values in datagridview cells?
i have 3 column is there...
i entered 1st column--->1st cell value then enter error will came
that means 2column-->1st cell is null ah..... 2column -->1at cell null values dot allow for datagridview

how to allow null values in datagridview cell?

推荐答案

private void dataGridView1_CellFormatting(object sender,
    DataGridViewCellFormattingEventArgs e)
{
    String value = e.Value as string;
    if ((value != null) && value.Equals(e.CellStyle.DataSourceNullValue))
    {
        e.Value = e.CellStyle.NullValue;
        e.FormattingApplied = true;
    }
}







请参考以下链接

https:// msdn。 microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle.nullvalue(v=vs.110).aspx [ ^ ]


这篇关于如何在datagridview单元格中允许空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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