Topic: ComboBox Value...

As a beginner this mayby have a Obvious solution, but i can´t get hold of it.
I have a form with a ComboBox with values from a directory table.

'Value 1'
'Value 2'
'Value 3'
'value 4'

Depending of what i enter in another field [FIELD 1]  in the form i want to fill in the ComboBox automatically with one of the values contained in the ComboBox.

If Value of FIELD 1 = 'A known keyword'' Then fill the ComboBox with the value 'Value 3'

Form1.ComboBox1.Text := *Value 3',
Form1.ComboBox1.Value := *Value 3',

Does not work. It must have something to do with the directory table index, or..??

Hope someone gets my problem

Re: ComboBox Value...

An example

procedure Form1_Edit1_OnChange (Sender: TObject);
begin
    if Form1.Edit1.Text = 'A known keyword' then Form1.ComboBox1.ItemIndex := 2;
end;
Dmitry.

Re: ComboBox Value...

Hi, again.. Thank´s for answer...

That was a part of the problem...

'Form1.ComboBox1.ItemIndex := 2' is pointing to the second value in the list, but i don´t know what indexnumber it has??

For explanation.

I register a purchase in my database, and if the Company is 'Drive Software" i know that the category for the purchase should be 'Software".
How do i get the index number for 'Software" in the dictionary table? Is i possible to scan through the list to find the Index?

4 (edited by derek 2019-03-26 10:09:55)

Re: ComboBox Value...

Hi Hedan,
You could try doing it like this (see attached).
However, I'm not sure how practical your approach of trying to automate a combobox selection from a list of keywords hard-coded into your script can be. 
Rather than scripting, perhaps a better approach might be to use a sort of 'reverse' parent combobox where you manually select your keyword value from the child combobox (rather than in the parent, as is usual) and it automatically fills in the corresponding value from the parent combobox. 
But even then, it's a rather unusual requirement.
Derek.

Post's attachments

Attachment icon hedan.zip 338.18 kb, 406 downloads since 2019-03-26 

Re: ComboBox Value...

Hi Derek,

Ok, i hear you. mayby not my best idea. :-)

Re: ComboBox Value...

This is how it could work if you do it with comboboxes - the association between keywords and categories is taken out of the script and can therefore be maintained by anyone.
This is okay if you need to analyse activity at both 'keyword' and 'category' levels, but if you just only to see activity at the 'category' level, I think I'd just use a single combobox, selecting values manually;  you can always make your combobox 'searchable' to speed things up, if that's your concern.
Derek.

Post's attachments

Attachment icon hedan2.zip 337.83 kb, 470 downloads since 2019-03-26