Derek Dowle

I am using a combobox on a form in VFP9.

The form has a series of comboboxes which assist the user in filtering records.

Each combobox has RowSourceType = 2 and RowSource = "the name of the cursor"

Each combobox displays the correct list of options when the form is run.

When the form is run all the boxes appear empty.

I need one of the comboboxes to display a default value when the form is run, which the user then has the option of changing.

The cursor contains three fields; field1, field2 & field3.

I have set .BoundColumn = 3

.ColumnCount = 3

.ColumnWidths = 35,25,0

There is no control source given.

In the .init of the combobox I have the code THIS.Value = m.cIDRef. Variable m.cIDref being the equivalent of data contained in field3 of the Cursor.

Can a form be opened with a combobox showing a default value

If yes could someone please advise where I am going wrong.

Many thanks.

Re: Combobox Default Value

Naomi Nosonovsky


You may put

thisform.myCombo.ListIndex = 1


thisform.myCombo.DisplayValue = 'My default value'

in the Init of the form.

Re: Combobox Default Value


What you're doing is right. Are you sure that value exists Here is a sample:


oForm = CREATEOBJECT('myForm')


DEFINE CLASS myForm as Form


ADD OBJECT myCombo as combobox ;

WITH rowsourcetype=2,rowsource="customer.Company,Contact,cust_id",;



USE (_samples+'data\customer')


PROCEDURE mycombo.init

lcCustomerID = "CENTC"

this.Value = m.lcCustomerID



Re: Combobox Default Value

Derek Dowle

Thankyou to Naomi and Cetin for giving me the direction to solve the problem.

I had previously tried using the equivalents of:

thisform.myCombo.ListIndex = 1

thisform.myCombo.DisplayValue = 'myDefaultValue'

this .value = m.lcCustomerID

The problem was actually in the RowSource. I had created a cursor to hold the data so that I need not keep a table open. With the RowSourceType = 2 the combobox was displaying the list as intended.

Changing the RowSourceType to 3 and using an SQL statement for the RowSource combined with your responses has solved the problem.

Is there any reason why the original RowSourceType and RowSource combination did not work

Re: Combobox Default Value

Naomi Nosonovsky


I think you need to give us a bit more info. I usually set my combos to alias or array (just a habit) and though I did have some problems in the past not related to your question, I don't think I ever had any problems setting a value.

Is your combo bound or unbound Are you using numerical value for the combo's value by any chance

Re: Combobox Default Value



It's not a problem of rowsource (my sample uses RowSourceType = 2). But probably you didn't create your cursor with nofilter and closed all the cursors referencing underlying table, I don't know what exactly you did.

However I suggest you to use RowSourceType = 3 whenever there is a chance to do soSmile

Re: Combobox Default Value

Derek Dowle


You spotted the mistake 'NOFILTER' was missing from my code to create the cursor.