DataGridCell 空集 DbNull.value [英] DataGridCell empty set DbNull.value

查看:73
本文介绍了DataGridCell 空集 DbNull.value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用数据集填充数据网格,并且我已经验证了我的数据集的可为空值 -

I am populating a datagrid with a dataset and I have my dataset verified for nullable values -

我的问题是:

当数据集正在验证时,它发现空行并且不显示错误.我想用 DBNull.value 定义空单元格.有什么办法吗?我发现了一个名为 TargetNullValue 的属性可以工作?

When the dataset is validating, it found empty rows and the errors are not displayed. I would like to define the empty cells with a DBNull.value. Is there any way to do it ?. I have found a property named TargetNullValue that could work ?

推荐答案

我找到了一种方法,通过进行转换

I found a way to do it, by making a convertion

 public class ConvertStringToDBNull : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo cufo)
    {

        if (value is string)
        {
            if (value.ToString() == string.Empty)
            {
                return DBNull.Value;
            }
        }
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cufo)
    {

        if (value is string)
        {
            if (value.ToString() == string.Empty)
            {
                return DBNull.Value;
            }
        }
        return value;
    }

}

这篇关于DataGridCell 空集 DbNull.value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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