Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在datagridview c中验证行#_C# - Fatal编程技术网

C# 如何在datagridview c中验证行#

C# 如何在datagridview c中验证行#,c#,C#,为什么验证总是拒绝编辑(行e.Cancel=true;) 准确地验证一行是什么意思?您能更具体一点吗?如果单元格值为空,则不应转到新行。请检查我的代码并告诉我更正。您需要更具体地说明您需要的内容以及您已经/已经尝试的内容。事实上,甚至尝试分析问题都非常困难。请添加一个描述性的解释,说明您需要什么以及为什么它不起作用。 private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArg

为什么验证总是拒绝编辑(行
e.Cancel=true;


准确地验证一行是什么意思?您能更具体一点吗?如果单元格值为空,则不应转到新行。请检查我的代码并告诉我更正。您需要更具体地说明您需要的内容以及您已经/已经尝试的内容。事实上,甚至尝试分析问题都非常困难。请添加一个描述性的解释,说明您需要什么以及为什么它不起作用。
    private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
    {
        DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
        DataGridViewCell Docnamecell = row.Cells[dataGridView1.Columns[0].Index];
        DataGridViewCell Gendercell = row.Cells[dataGridView1.Columns[1].Index];
        DataGridViewCell Addresscell = row.Cells[dataGridView1.Columns[2].Index];
        DataGridViewCell Contactnocell = row.Cells[dataGridView1.Columns[3].Index];
        DataGridViewCell Datecell = row.Cells[dataGridView1.Columns[4].Index];
        e.Cancel = !(IsDoc(Docnamecell) && IsGender(Gendercell) && IsAddress(Addresscell) && IsContactno(Contactnocell) && IsDate(Datecell));
        e.Cancel = true;
    }
    private Boolean IsDoc(DataGridViewCell cell)
    {
        if (cell.Value == null)
        {
            MessageBox.Show("Enter Docname");
        }
        return false;
    }
    private Boolean IsGender(DataGridViewCell cell)
    {
        if (cell.Value == null)
        {
            MessageBox.Show("Enter Gender");
            return false;
        }
        return true;
    }
    private Boolean IsAddress(DataGridViewCell cell)
    {
        if (cell.Value == null)
        {
            MessageBox.Show("Enter Address");
            return false;
        }
        return true;
    }
    private Boolean IsContactno(DataGridViewCell cell)
    {
        if (cell.Value == null)
        {
            MessageBox.Show("Enter Contact no");
            return false;
        }
        return true;
    }
    private Boolean IsDate(DataGridViewCell cell)
    {
        if (cell.Value == null)
        {
            MessageBox.Show("Enter Date");
            return false;
        }
        return true;
    }
}
private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
    DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
    DataGridViewCell Docnamecell = row.Cells[0];
    DataGridViewCell Gendercell = row.Cells[1];
    DataGridViewCell Addresscell = row.Cells[2];
    DataGridViewCell Contactnocell = row.Cells[3];
    DataGridViewCell Datecell = row.Cells[4];
    e.Cancel = !(IsDoc(Docnamecell) && IsGender(Gendercell) && IsAddress(Addresscell) && IsContactno(Contactnocell) && IsDate(Datecell));
}