【发布时间】:2017-10-21 18:55:41
【问题描述】:
我有两种形式。 在 form1 上是一个 datagridview 和按钮。 在 ButtonClick 事件中,正在验证 datagridview,如果为 null 或为空,则返回,否则 form2 应该打开。 (这是语法) 但是当应用程序运行并且要打开 form2 时,它会填充大约 15 个 form2。 请问我如何阻止人口 这是代码
private void button3_Click(object sender, EventArgs e)
{
this.dataGridView1.ClearSelection();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.IsNewRow) { return; }
foreach (DataGridViewCell cell in row.Cells)
{
// Validating cell value
var regexItem = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9 ]$");
if (cell.Value == null || !regexItem.IsMatch(cell.Value.ToString()))
{
cell.Style.BackColor = Color.Red;
}
}
}
this.Hide();
resultVV f2 = new resultVV();
f2.Show();
}
【问题讨论】:
标签: c# winforms datagridview