| | | | Browse by category |
Article ID: 155
Last updated: 04 Jun, 2018
Problem
Is there an exception-safe way to change read-only cells?
Cause
Action
If you are executing operations that might throw exceptions, you might consider a more exception-safe way. Declare a class that unlocks the grid in the constructor and locks it again in the destructor.
class CGridUnlock { public: |
|||
CGridUnlock (CGXGridWnd* grid, BOOL bUnlock = TRUE) | |||
: pGrid(grid) { if (bUnlock) Unlock(); } | |||
~CGridUnlock() { Lock(); } void Unlock() { pGrid->SetReadOnly (FALSE); } void Lock() { pGrid->SetReadOnly (TRUE); } CGXGridWnd* pGrid; |
|||
}; |
To use this, just declare a CGridUnlock object whenever you want to unlock the grid. The grid will lock again when the class goes out of scope. If you want finer control, then call the Lock()/Unlock() methods of the class. If an exception is hit and the catch is outside the scope of the object, then the destructor will lock the grid again.
This article was:
Helpful |
Not helpful
Report an issue
Article ID: 155
Last updated: 04 Jun, 2018
Revision: 3
Views: 2404
Posted: 10 Jan, 2001 by
Meltreger B.
Updated: 04 Jun, 2018 by
Meltreger B.
Others in this category
Powered by KBPublisher (Knowledge base software)