I am getting an exception when trying to use MessageBox within my CellValidating event. I check in the cellvalidating event if the cell has null value , I show a MessageBox and set e.Cancel=true; However the use of the MessageBox gives an exception as follows-

Object Reference not set to instance of object

My main aim is to prevent user from deleting the cell's value via grid edit.So, I need to throw a prompt and bring back the focus to the same cell, everytime when cell value is empty on tabbing out of the call.Any idea what might be causing this exception? Below is the code in my CellValidating event

 if ((columnName == "Date") && e.Value == null && e.ActiveEditor != null)

            cell.Value = e.OldValue;

            MessageBox.Show("Please specify a date.", "Date Field is Required");


Below is the StackTrace for the error-

Application does not support just-in-time (JIT) debugging. See the end of this message for details.

************** Exception Text ************** System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.WinControls.UI.GridViewEditManager.EndEditCore(Boolean validate, Boolean cancel) at Telerik.WinControls.UI.BaseGridBehavior.OnMouseDown(MouseEventArgs e) at Telerik.WinControls.UI.RadGridView.OnMouseDown(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at Telerik.WinControls.RadControl.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Additional Detail- The exception doesn't occur when I normally Tab OUt of the cell, but when I scroll to the extreme Right while my cell that I was editing prior to scrolling is still in edit mode, and while I scroll my prompt (MessageBox) shows up and on clicking Ok error is shown.

0 Answers