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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default value and interactive change issue of combo in VFP9

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
Hi there,
on a form I put the combo with few values "AAA", "BBB", and "CCC". Depending of combo selected value then in textbox is displayed proper text.
For Combo1:
Rowsource: AAA,BBB,CCC
Rowsourcetype=1

In order to set up default value for combo and avoid blank value for combo I put in Activate events of form: Thisform.combo1.ListIndex=1. In InteractiveChange of combo1 I wrote
Code:
DO case
	CASE thisform.combo1.DisplayValue="AAA"
	thisform.text3.Value="Director"
	CASE thisform.combo1.DisplayValue="BBB"
	thisform.text3.Value="Secretary"
	CASE thisform.combo1.DisplayValue="CCC"
	thisform.text3.Value="Driver"
endcase
but when I started form combo get wanted value (AAA) then in text3 was not any value (I expected Director), seems like InteractiveChange of Combo1 isn't fired? What I shall to set up in order to get this functional? Thanks for your time.

There is no good nor evil, just decisions and consequences.
 
Hi jimstarr,
thanks for stopping by. Do I need also to put the same code into ProgrammaticChange and InteractiveChange in order to keep refresh of text3 with each change of Combo1?

There is no good nor evil, just decisions and consequences.
 
Eliot,

The behaviour you described is what I would expect.

You are correctly populating the comob. But the textbox will only get populated when the user selects a value of from the combo - not when the form is activated.

This is easy to fix.

First, don't put any code in the Activate event. If you do, the combo will be re-initialised every time the user clicks away from the form and then clicks back again, which is not what you want. Better to put the code (for setting the combo's values) in the combo's Init.

Next, add code to the textbox's Init. The only code you need there is::

this.value = "Director"

Lastly, keep the combo's InteractiveChange exactly as it is. It will fire whenever the user selects a value from the combo, which is what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Ok MikeLewis, thank you. I'll try this solution and cut off suggested code in Form's region. As far as I could to see, in combo1 a user shall be able to pick job position and in Text3 to show names or so... maybe is better to make combo with 2 column based on SQR that select position and name of person and just put default value of Combo1 and then read contents of second column of combo1, right?
Thanks.

There is no good nor evil, just decisions and consequences.
 
maybe is better to make combo with 2 column based on SQR that select position and name of person and just put default value of Combo1 and then read contents of second column of combo1, right?

No. I think your original plan is better. The problem was that the code to initially populate the texbox wasn't firing. Just store the default value of the textbox (Director) as I suggested, and move the other code from the form's Activate to the combo's Init. And keep the InteractiveChange as it is.

I think that will give you a better interface than a 2-column combo (but that's just my personal opinion).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
One thing is bad aboiut this proposed solution, you set textbox to "Director" in it's init and in the combobox InteractiveChange. If the latter code is changed, you also need to change the textbox init.

In short: this solution breaks the DRY rule (don't repeat yourself) you have two places, where the vlaue of the textbox is hardcoded.

It would actually be nicer the textbox would be inited per event.

I agree it's bad to put the listindex=1 into the form.acitvate, but I'd suggest you have a combobox init that puts Listindex=1 AND calls a user defined combobox method, which is also called by Combo1.InteractiveChange(). This way the code is written once and executed for initialisation and everytime a user makes an interactive change.

It's often good to have one method you can call from both interactivechange, programmaticchange and init, which does something you want done however the combobox value changes.

If you put it that way, whatever you change in the userdefined new method is done.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top