Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ComboBox showing blank at first

ComboBox showing blank at first

ComboBox showing blank at first

Hello colleagues!

I have a ComboBox with this code in the Init procedure:

CODE -->


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,

RE: ComboBox showing blank at first

I put:

CODE -->

 this.Style= 2        && Dropdown List 

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

Thank you,

RE: ComboBox showing blank at first

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:


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.


RE: ComboBox showing blank at first

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.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close