We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Object reference not set to an object error in CommandStack

Hi, I've got an class which inherits from GridControl. In one of the properties, which is getting called during initialisation, I call CommandStack.Clear(), and it throws an "Object reference not set to an object" error (CommandStack itself is not null). If I do a quick watch on the object before the call, it doesn't throw this exception, so I assume the problem is due to some object which gets created by a property get. Could you please tell me what I need to do to fix this problem. Thanks, Sue

1 Reply

AD Administrator Syncfusion Team September 18, 2003 05:53 AM UTC

Clear calls: undoStack.Clear(); redoStack.Clear(); So, these objects must not have been created at the point you are trying to call Clear. You can force their creation by just referencing their public property analogs, as they are created on demand as your access the public properties, UndoStack and RedoStack. So, this code may work.
if(CommandStack.UndoStack.Count > 0 || 
           CommandStack.RedoStack.Count > 0)
      CommandStack.Clear();

Loader.
Up arrow icon