Qing Ryder

Qing Ryder

  • NA
  • 202
  • 17.3k

Form2 Populates on ButtonClik

Oct 21 2017 9:21 AM
i have two forms.
on form1 is a datagridview and button.
On ButtonClick event, the datagridview is being validated and if null or empty, it returns back else form2 should open. (that is the syntax)
but when the application runs, and form2 is to be open, it populates about 15 of form2.
please how do i stop the population
here is the code
  1. private void button3_Click(object sender, EventArgs e)  
  2.         {  
  3.              this.dataGridView1.ClearSelection();  
  4.                   foreach (DataGridViewRow row in dataGridView1.Rows)  
  5.                      {  
  6.                        if (row.IsNewRow) { return; }  
  7.                        foreach (DataGridViewCell cell in row.Cells)  
  8.                        {  
  9.                            // Validating cell value  
  10.                            var regexItem = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9 ]$");  
  11.                            if (cell.Value == null || !regexItem.IsMatch(cell.Value.ToString()))  
  12.                            {  
  13.                                cell.Style.BackColor = Color.Red;  
  14.                            }  
  15.                             
  16.                        }  
  17.                     }  
  18.                this.Hide();  
  19.                resultVV f2 = new resultVV();  
  20.                f2.Show();  
  21.        } 
 

Answers (4)