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


Derek,

You may put

thisform.myCombo.ListIndex = 1

or

thisform.myCombo.DisplayValue = 'My default value'

in the Init of the form.






Re: Combobox Default Value

CetinBasoz

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

PUBLIC oForm

oForm = CREATEOBJECT('myForm')

oForm.Show

DEFINE CLASS myForm as Form

datasession=2

ADD OBJECT myCombo as combobox ;

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

boundcolumn=3,columncount=3,columnwidths="200,200,0"

PROCEDURE load

USE (_samples+'data\customer')

ENDPROC

PROCEDURE mycombo.init

lcCustomerID = "CENTC"

this.Value = m.lcCustomerID

endproc

enddefine






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

Derek,

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

CetinBasoz

Derek,

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

Cetin

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

Thankyou