Ways of how to change forecolor on win controls when value/property changes

Ways of how to change forecolor on win controls when value/property changes

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


GeorgeG posted on Friday, March 23, 2007

I need to change the color of a control ie textbox, combobox and checkbox when the user changes the value. After saving or moving to the next row forecolor should revert to the original color. I am thinking to inherit ftom BusinessBase and override PropertyHasChanged and save the property name in a list. In addition, to have some methods for clearing the list, check the list if contains a particular name. On the winform loop through the controls and check if the name is in the list and then change the color

Anybody implemented something like this and how was it done?

 

ajj3085 replied on Friday, March 23, 2007

George,

I don't think you need to do anything fancy.  Just listen to the CurrentItemChanged on the bindingsource component which is tied to your bo.  In that event, check the property name and update the color of the appropriate control.

After a save, just reset the colors back.

GeorgeG replied on Monday, March 26, 2007

Will try CurrentItemChanged without extending the CSLA framework. Thanks

tetranz replied on Friday, March 23, 2007

Remember that you can bind data to any property of a control, not just the obvious common properties like Text, Checked etc. You can bind to BackColor just as easily. You get to the other properties via the "Databinding / Advanced" button in the Properies windows of a control.

I've done this sort of thing by a BO having a property of type System.Drawing.Color. This is set within the BO to output the appropriate color. The control's backcolor or whatever is bound to that. That's worked fine although I'm aware that its somewhat "bad" because it introduces some UI stuff into the BO but ... it got the job done.

Ross

Copyright (c) Marimer LLC