Topic: Search results on ComboBox

Hi,

Can display the result of search as selected item on ComboBox instead TableGrid ?

And Can I create customized list of ComboBox without needs to link in DataBase ?

Life is like a school;
One can learn and graduate or stay behind.

Re: Search results on ComboBox

if Combobox is connected to database then you can use this script

Form1.Combobox1.dbitemid := SQLExecute('select id from mytable where id = myID');

and Second Ans

Form1.combobox1.items.add('MyItem1');
            Form1.combobox1.items.add('MyItem2');
            Form1.combobox1.items.add('MyItem3');

3 (edited by FMR 2022-04-23 21:12:31)

Re: Search results on ComboBox

Hi,

I didn't figure out how to make the search, please see my project and show me my mistake, this code what I write:

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
Form1.ComboBox1.Items.Text := Form1.Edit1.Text;
end;

procedure Form1_Button2_OnClick (Sender: TObject; var Cancel: boolean);
begin
Form1.ComboBox1.dbUpdate;
Form1.Edit1.Clear;
end;

the search can find the result but the combobox show the first choice is blank


The second answer was great, work perfect.

Post's attachments

Attachment icon Search-ComboBox.zip 5.36 kb, 125 downloads since 2022-04-23 

Life is like a school;
One can learn and graduate or stay behind.

Re: Search results on ComboBox

Hi FMR,
Not too sure what you're trying to do but perhaps try it like this (see attached).
Derek.

Post's attachments

Attachment icon Search-ComboBox1.zip 337.71 kb, 131 downloads since 2022-04-24 

5 (edited by FMR 2022-04-24 05:47:35)

Re: Search results on ComboBox

derek wrote:

Hi FMR,
Not too sure what you're trying to do but perhaps try it like this (see attached).
Derek.


Derek,
Sorry, but I got simi answer. the form1.combobox1.dbItemID := 0; help me alot

Your code keep show me error message

Post's attachments

Attachment icon Search-ComboBox.zip 5.39 kb, 122 downloads since 2022-04-24 

Life is like a school;
One can learn and graduate or stay behind.

Re: Search results on ComboBox

FMR wrote:

Hi,

Can display the result of search as selected item on ComboBox instead TableGrid ?

And Can I create customized list of ComboBox without needs to link in DataBase ?

procedure Form1_ComboBox1_OnDropDown (Sender: TObject);
var
i :integer;
list :TStringList;
begin
  Form1.ComboBox1.Clear;

  list:=TStringList.Create;
  if ( Form1.Edit1.Text = '' ) then list.Text:=SQLexecute('SELECT group_concat(id, char(13) || char(10)) FROM a ') else
    list.Text:=SQLexecute('SELECT group_concat(id, char(13) || char(10)) FROM a WHERE aa LIKE "'+'%'+Form1.Edit1.Text+'%'+'"');

  for i := 0 to list.Count-1 do
    Form1.ComboBox1.Items.Add(SQLExecute('SELECT aa FROM a WHERE id='+list[i])) ;

  list.Free;
end;
Post's attachments

Attachment icon test.zip 4.47 kb, 157 downloads since 2022-04-24