Retrieve the data entered in DataGrid cell for validation

Madhu.b.rokkam
Posted by Madhu.b.rokkam under Windows Forms category on | Points: 40 | Views : 3433
private void dataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
string cellCOntent = dataGridView.CurrentCell.EditedFormattedValue.ToString();
//You can have your validation code here...
}
}


Get the cell content that you entered/edited in the datagrid.

Comments or Responses

Posted by: Alpesh on: 3/8/2011 Level:Starter | Status: [Member] | Points: 10
Another method for validation with cellvalidating event of datagrid.

private void DataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 1)
{
if (e.FormattedValue.ToString() == "")
{
// Write here message or validated action..
}
}
}
Posted by: Akiii on: 3/9/2011 Level:Bronze | Status: [Member] | Points: 10
good post......

Thanks and Regards
Akiii

Login to post response