2015-03-18 2 views
0
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; 
    } 
} 
+0

Что вы подразумеваете под _васификацией строки_ точно? Не могли бы вы быть более конкретными? –

+0

, если значение ячейки пустое, чем оно не должно идти в новую строку –

+0

, пожалуйста, проверьте мой код и скажите мне коррекцию –

ответ

1

Почему ваша проверка всегда отвергает редактирование (строка e.Cancel = 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)); 
} 
Смежные вопросы