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

ComboBox showing blank at first

Status
Not open for further replies.

SitesMasstec

Technical User
Sep 26, 2010
498
BR
Hello colleagues!

I have a ComboBox with this code in the Init procedure:
Code:
WITH THIS
   .AddItem("")
   .AddItem("Yes")
   .AddItem("No")
   .ListIndex=1
ENDWITH

This is because I do not want a pre displaying Yes or No when form opens.

Do I need to include AddItem("") or is there a way to show no option until the user clicks on the down arrow of the ComboBox?


Thank you,
SitesMasstec
 
I put:
Code:
 this.ListIndex=0
 this.Style= 2        && Dropdown List

and it worked as I needed. But is this a good practice?


Thank you,
SitesMasstec
 
Yes, because you can set ListIndex to 0.

I'd also recommend to set the Style to 2, Dropdownn list, because otherwise users cannot only pick from the two options Yes/No, but also enter any other text.
Notice, users can still also turn the value back to empty when the use CTRL+0.

The best control for giving a Yes/No decison is a checkbox, not a combobox. And an optiongroup also allows to switch between two or more options easier than a combobox allows. A checkbox allows you to start with .NULL. or -1 for undecided and once a user checks or unchecks the checkbox, he toggles between the checked and unchecked state, either .t. and .f., or 0 and 1, depending on whether you initially set it to .null. or -1. Again, just like with the combobox, CTRL+0 puts the checkbox back into the undecided state. To disallow that you could once mute this hotkey by doing this in main.prgt, for example:

Code:
On Key Label CTRL+0 *
The * means you instruct the key to execute a comment aka nothing. So you override the default behavior of resetting controls to the .null. state.

It's not a well known feature as this key combination CTRL+0 isn't Windows standard, it's specific to VFP applications. And it's not a bad idea to define this, also in case you'd like to allow users to get back to the undecided state of a combobox or checkbox. Because null values are most often unexpected and not handled by code, so they could lead to errors. If you want to allow to reset cehckboxes or comboboxes to their initial state you have the ResetToDefault() method and you could put a reset command button on forms to allow that, but in a manner you control which controls are reset to what values.


Chriss
 
Ha ha, that crossed over with my post.

Yes, it is good practice, it's also the first thing I recommended. Maybe take a loook into my further recommendations, too.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top