I'm sorry. You're absolutely right. I didn't pay attention to the value being changed. I was only noticing that the color was being changed and that the new color was being preserved as the editing continued.
It looks like you found a bug in the table, which will be fixed. For now, however, you can try a couple of quasi-workarounds, but there is no complete workaround.
You can ensure that the edited value is preserved by terminating the edit session prior to changing the color:
...
if (length > 20)
{
GetCtrlAttribute (panel, control, ATTR_TABLE_RUN_STATE, &state);
if (state == VAL_EDIT_STATE)
SetCtrlAttribute (panel, control, ATTR_TABLE_RUN_STATE, VAL_SELECT_STATE);
SetTableCellAttribu
te (panel, control, cell, ATTR_TEXT_COLOR, VAL_RED);
...
The problem is restoring the edit session on the cell. You can sort of do it by calling
SetCtrlAttribute (panel, control, ATTR_TABLE_RUN_STATE, state);
after changing the color. But the cursor will not be in the same position, and the entire text will be highlighted. You can kill the highlighting by faking a key afterwards:
FakeKeystroke (VAL_LEFT_ARROW_VKEY);
But the cursor will still be at beginning of the cell, which might make it jarring to someone who is trying to type into the cell.
If your user doesn't need to continue editing, then it's a bit easier. In that case, instead of restoring the run state, you should just make a different cell active, so that the highlighting goes away.
Neither of these are very good workarounds, but hopefully you might be able to use one of them. I'm sorry for the bug...
Luis Gomes
NI