I'm using Telerik.WinControls.GridView version 2012.2.912.40.
I validate a cell value in cell validating event.
I set e.Cancel = true in CellValidating event and then delete row of that cell with a command cell click event.
when the gridview's row count reach to zero and double click the gridview error occur "Exception thrown: 'System.NullReferenceException' in Telerik.WinControls.GridView.dll".
private void gvStockItemDetail_CellValidating(object sender, CellValidatingEventArgs e)
{
if (!string.IsNullOrEmpty(Convert.ToString(e.Row.Cells["Stock ID"].Value)) && column.Name == "Quantity")
{
if (Convert.ToDecimal(string.IsNullOrEmpty(Convert.ToString(e.Value)) ? 0 : e.Value) <= 0)
{
e.Cancel = true;
e.Row.Cells["Quantity"].BeginEdit();
e.Row.ErrorText = BOL_Global_Message.STOCK.Msg_Quantity;
}
else
{
e.Row.ErrorText = string.Empty;
}
}
}
private void gvStockItemDetail_CommandCellClick(object sender, EventArgs e)
{
if (gvStockItemDetail.CurrentRow.Index >= 0)
{
gvStockItemDetail.Rows.RemoveAt(gvStockItemDetail.CurrentRow.Index);
}
}