How to validate cells entries and provide feedback

I have been struggling with trying to figure out a reasonable way to validate the contents of a cell regardless of how the edit text is set (clicking on another cell, tabbing to another cell, pressing enter, clicking a different control) and to then provide a message to the user. As we discussed in January in another thread, cell balloons combined with Oncellvalidate almost meets this requirement in that a balloon can be displayed if the user presses enter or changes cells by tabbing to another cell. However, setting the edit text by clicking a different cell does not trigger the balloon when valid:=false in oncellvalidate. At the time you said you would consider changing the behavior so that the effect of changing cells is consistent regardless of whether it is by mouse or keyboard, but the change does not seem to have been made.

I tried to work around this limitation by using Showmessage inside Oncellvalidate but when valid:=false, but that results in showmessage being display twice.

Since I want to validate that the entry is an integer in the range 0-80 I considered using a spinedit inplace editor but decided against it because I don't want a spinner. I suppose I could use a custom inplace editor with an advedit, but I was wondering if there might be a simpler alternative.

The question comes down to: how can I validate the contents of a cell and display a popup message when the edit text is set, regardless of how the text is set (enter, tab, mouse, etc.)?

Thank you!

You cannot show a messagebox in the OnCellValidate event. The reason is simple. A messagebox takes the focus away from the inplace editor. Taking the focus away affects the process to terminate editing, i.e. it forces again to terminate editing while OnCellValidate is a step in the terminating process. If you want to display a messagebox, a possible solution is to set a flag according to whether the edited value is acceptable or not and use this flag from the OnCellEditDone event to show a messagebox. OnCellEditDone is triggered AFTER the editing is terminated, hence, taking the focus away from the grid with a messagebox doesn't affect the editing process anymore.