如果单元格中有任何空值,请防止用户更改datagrid行. [英] Prevent user change datagrid row if there is any null values in the cells.

查看:78
本文介绍了如果单元格中有任何空值,请防止用户更改datagrid行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个数据网格,如果任何一个数据网格单元为空,我不希望用户更改到其他任何行.有人可以帮忙吗?

Hello all,

I have a datagrid,and i dont want the user to change go to any other rows if any of the datagrid cells is empty.Can anyone help?

Thnx in advance!

推荐答案

先检测然后禁用.

检测:
First detect and then disable.

Detect:
if myGrid.CurrentCell.Value == null



禁用:



Disable:

myGrid.Rows[0].ReadOnly = True



在此处引用类似的帖子 [



Refer similar post here [^]


 private void datagridview1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (datagridview1.Rows[e.RowIndex].Cells[4].FormattedValue.ToString() == string.Empty)
            {
                e.Cancel = true;
                datagridview1.Rows[e.RowIndex].Cells[4].ErrorText = "Mandatory";
            }
            else
            {
                datagridview1.Rows[e.RowIndex].Cells[4].ErrorText = string.Empty;
            }
}

 private void datagridview1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (e.ColumnIndex == 4)
            {
                if (e.FormattedValue.ToString() == string.Empty)
                {
                    datagridview1[e.ColumnIndex, e.RowIndex].ErrorText = "Mandatory";
                    e.Cancel = true;
                }
                else
                {
                    datagridview1[e.ColumnIndex, e.RowIndex].ErrorText = string.Empty;
                }
            }
}


这篇关于如果单元格中有任何空值,请防止用户更改datagrid行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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