I have a gridview with 3 columns and I want to make sure that all cells in the row have a value in them. If col0 is null and the user goes back and enterd data, the event does not detect the changes and just gets stuck in the col0 cell. As you can see, I tried a couple of different ways. Below is my code:
private void dgvCatagories_CellValidating(object sender, CellValidatingEventArgs e)
{
try
{
GridViewDataColumn column = e.Column as GridViewDataColumn;
// if (string.IsNullOrEmpty((string)e.Row.Cells["Col0"].Value) || ((string)e.Row.Cells["Col0"].Value).Trim() == string.Empty ||
// string.IsNullOrEmpty((string)e.Row.Cells["Col1"].Value) || ((string)e.Row.Cells["Col1"].Value).Trim() == string.Empty ||
// string.IsNullOrEmpty((string)e.Row.Cells["Col2"].Value) || ((string)e.Row.Cells["Col2"].Value).Trim() == string.Empty)
if (e.Row is GridViewDataRowInfo && column != null && column.Name == "Col0" ||
e.Row is GridViewDataRowInfo && column != null && column.Name == "Col1" ||
e.Row is GridViewDataRowInfo && column != null && column.Name == "Col2")
{
e.Cancel = true;
((GridViewDataRowInfo)e.Row).ErrorText = "Cell Can Not Be Blank";
}
else
{
((GridViewDataRowInfo)e.Row).ErrorText = string.Empty;
}
}
catch (Exception ex)
{
LogFile(ex.Message, ex.ToString(), "dgvCatagories_CellValidating", this.FindForm().Name);
}
}