OT: Event v. Property

OT: Event v. Property

Old forum URL: forums.lhotka.net/forums/t/301.aspx


esteban404 posted on Wednesday, June 07, 2006

I've been handed a request to make all of the fields on a Win form yellow (highlighted) if they have no entered data values. I can do it via property and databinding or via event handling. Events always seemed a little more cumbersome and maintenance heavy to me.

I have an idea to use a 32 bit int value to hold a bit array each bit initialized to 0 (false) and use the property for each public field to help set the HasValue property of the field to true if it's not null. So that means there'd be a public property for each of the used bit fields, but it would not require a lot of interaction and databinding would allow the display color to change automatically. Now the form processes a lot of changes on each field, I've seen the same event fire up to 5 times for one change/check. It just seems a waste.

Has anyone got an opinion or tried something like this? I'm wondering if the benefit is worth the code.

_E

RockfordLhotka replied on Wednesday, June 07, 2006

Why not write an extender control that looks at the content of the control and sets its colors appropriately?

What you are describing certainly isn't something that should be in your business object - as it is a pure UI artifact. So the solution should reside in the UI, and Microsoft provides this extender control concept exactly for this type of issue.

You can look at Chapter 5 to see how I implemented the ReadWriteAuthorization control for some ideas, and there are other examples of extender controls on the web as well.

esteban404 replied on Wednesday, June 07, 2006

Thanks for that Extender Control bit <s> of information. I just asked about writing extender controls for a web project. I don't see why it'd be a big deal for Windows forms. Guess I just never thought of it.

_E

Copyright (c) Marimer LLC