Topic: ComboBox

I have on a combobox 3 choices. (Choice 1, Choice 2, Choice 3)
every time I call the form I want to have the first Choice written on the Combobox and not to be blank.
The combobox is not from a record field.

Re: ComboBox

Hello

I think there is a default index in the object inspector. Set it to 1 instead of 0 and that should do the trick

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

3 (edited by v_pozidis 2015-12-18 10:49:53)

Re: ComboBox

I know but it doesn't work when it is with a script.

The combobox is empty and I <<fill>> it using  a script
ComboBox1.Items.Add ('Choice 1');
ComboBox1.Items.Add ('Choice 2');
ComboBox1.Items.Add ('Choice 3');

So the values are not from a record, the combobox is not linked with any table.

Everytime I open the form the combobox is blank, until I click on it.

I need the ComboBox every time I open the form to have the first Choice, and I think that this will hapend only with a script, but I do not know the way to write it.

4 (edited by mathmathou 2015-12-18 10:58:42)

Re: ComboBox

Sorry, I misunderstood your question. smile


If your default choice is number 1 in list, did you try ::


procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.ComboBox1.Items.Add ('Choice 1');
    Form1.ComboBox1.Items.Add ('Choice 2');
    Form1.ComboBox1.Items.Add ('Choice 3');
    Form1.ComboBox1.ItemIndex := 0;
end;

If you want to turn back to empty Combobox on show, put ItemIndex := -1


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: ComboBox

Also you should to add Clear function

procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.ComboBox1.Items.Clear;
    Form1.ComboBox1.Items.Add ('Choice 1');
    Form1.ComboBox1.Items.Add ('Choice 2');
    Form1.ComboBox1.Items.Add ('Choice 3');
    Form1.ComboBox1.ItemIndex := 0;
end;
Dmitry.

Re: ComboBox

Haaaaa Dmitry... clever smile


This is to come back to default choice on next OnShow event right ?

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: ComboBox

Right.

Dmitry.

8 (edited by v_pozidis 2015-12-18 11:37:56)

Re: ComboBox

My Mistake was that I dind't write the script    Form1.ComboBox1.ItemIndex := 0;
Instate that I choose from the Object for the combobox the DefaultIndex=1

Thanks for your help....once again