Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Question

Status
Not open for further replies.

JBalcerzak

Programmer
Sep 5, 2002
73
US
I've got a combo box on a form which is populated from one table and stores the value in another. I've also got a label on my form which I would like to change forecolor based on the value of the combo. In the refresh method of the label I've got the following

do case
case products.status = 0
this.forecolor = rgb(0,0,0)
case products.status = 1
this.forecolor = rgb(0,128,0)
etc, etc.

otherwise
this.forecolor = rgb(x,x,x)
endcase

I'm calling the form refresh method (i.e. thisform.refresh() ) from the interactive change method of the combo box. However, my label isn't changing color - shouldn't the form refresh method fire the refresh methods of all the child controls? I could change the color directly from the interactive change method but I want the label to update the color when the form is loaded as well if the data is already set. Any ideas?
 
Make sure you have:
DODEFAULT()
after the code you've listed above.

Rick
 
JBalcerzak,

The way I've handled that sort of situation is to write add a method to the form which updates the label colour, and call that method both from the form's Init and the combo's InteractiveChange.

Mike


Mike Lewis
Edinburgh, Scotland
 
JBalcerzak,

Of course, the label base class doesn't have a refresh method which is probably why your label's refresh method isn't called when you call the form's refresh.

You would have thought a VFP form would look for the refresh method in all of it's contained objects, but apparently not! This is by design of course, not a bug!

Stewart
 
Stewart,
Good catch, since I've been using 8.0 much of the time since I got the beta last year, I'd forgotten that 8.0 is the first version to include a Refresh method for Labels!

Rick


 
Came up with an interesting solution - calling thisform.refresh from the interactive change didn't to store my change from the combo. I ended up putting my call to refresh in the mouse leave event as once the item is selected, the mouse is now out of the hot area for the combo, thus firing the refresh event for the form, which cascades down to the label because
 
mouse leave event?

What happens when the user doesn't use the mouse but instead uses the keyboard to make their selection?

Slighthaze = NULL
 
Argh - back to the drawing board - good catch - didn't think of that one!
 
Best I can think of is to call refresh in LostFocus method as well - If I put that in KeyPress or Click, the control won't allow me to change the value of the combo. The LostFocus refresh would work for the mouse clicks too, but its a little more spiffy to have the label change as soon as the mouse selects the new value - my users require instant gratification!
 
This doesn't work when you run it from a prg in VFP?

PUBLIC oForm
oForm = CREATEOBJECT("clstest")
oForm.visible = .t.

DEFINE CLASS clstest AS form


DoCreate = .T.
Caption = "Form"
Name = "clstest"


ADD OBJECT combo1 AS combobox WITH ;
RowSourceType = 1, ;
RowSource = "RED,GREEN,BLUE,BLACK", ;
Height = 24, ;
Left = 60, ;
Top = 84, ;
Width = 204, ;
Name = "Combo1"


ADD OBJECT label1 AS label WITH ;
AutoSize = .T., ;
FontSize = 16, ;
BackStyle = 0, ;
Caption = "Label1", ;
Height = 27, ;
Left = 60, ;
Top = 36, ;
Width = 65, ;
Name = "Label1"


PROCEDURE combo1.InteractiveChange
LOCAL nColor, cValue
cValue = this.Value

DO case
CASE cValue = "RED"
nColor = 255
CASE cValue = "GREEN"
nColor = 32768
CASE cValue = "BLUE"
nColor = 16711680
CASE cValue = "BLACK"
nColor = 0
ENDCASE

this.Parent.label1.ForeColor = nColor
ENDPROC


ENDDEFINE


Slighthaze = NULL
 
I'll dump that in a form to day and give it a try. Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top