Distinguishing programmatic change from user change.

S

Sin Jeong-hun

For example, suppose if it is a TreeView. "AfterSelect" occurs both
for programmatic selection (TreeView.SelectedNode = something;) or
user selection (by mouse click or keyboard navigation). When the user
selects a node, then the program should change the model accordingly,
but when the model is changed by itself the program should change the
selected node to reflect the change. Not only for TreeView, but this
is generally the same for other UI controls. Another example is the
CheckedChanged of the CheckBox.

But sometimes I need to distinguish those two kinds. I have looked at
the source code of an application that my company releases to
customers, and the program simply(?) removed the eventhandler when it
needs to programatically change the UI control then added the
eventhandler again. The program itself had a bug that sometimes the
same eventhandler added twice due to some logical error. On the other
hand, I have used some sort of boolean flags for this. But neither
seems to be a clean solution.

What is the best practice to distinguish programmatic change from user
change for UI control states? As always, thank you for your
suggestions.
 
J

Jeff Johnson

But sometimes I need to distinguish those two kinds. I have looked at
the source code of an application that my company releases to
customers, and the program simply(?) removed the eventhandler when it
needs to programatically change the UI control then added the
eventhandler again. The program itself had a bug that sometimes the
same eventhandler added twice due to some logical error. On the other
hand, I have used some sort of boolean flags for this. But neither
seems to be a clean solution.

The Boolean flag is what I have always used, and I've never felt that it
wasn't "clean." Some people think complex = good, simple = lazy (and
therefore bad). Those people are wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top