Board index » delphi » ComboBox with incremental search ?

ComboBox with incremental search ?

Hi !
I'm quite new to Delphi programming.
I'd like to know how to allow the user to select a name in a DbComboBox but
at the same time permit him to enter a new name. For example, you type in
the first letters and if a correponding name already exists, the name
appears highlighted, and you simply select it. If not, then the user can
type it all in and it will be saved to the table.
Is there  already a component that does this job ? Do I have to code a
special procedure? Did I forget some properties of combo boxes or what ?

Any help appreciated !
Thanks in advance !
Lina

 

Re:ComboBox with incremental search ?


Quote
Lina Scarpellini wrote:

> Hi !
> I'm quite new to Delphi programming.
> I'd like to know how to allow the user to select a name in a DbComboBox but
> at the same time permit him to enter a new name. For example, you type in
> the first letters and if a correponding name already exists, the name
> appears highlighted, and you simply select it. If not, then the user can
> type it all in and it will be saved to the table.
> Is there  already a component that does this job ? Do I have to code a
> special procedure? Did I forget some properties of combo boxes or what ?

> Any help appreciated !
> Thanks in advance !
> Lina

Hi Linda,

I had the same problem.
But I solved it partially by using an extra button and the following
code:

   procedure TForm1.Button1Click(Sender: TObject);
   var
     NewName : string;
   begin
     NewName := DBComboBox1.Text;
     DBComboBox1.Items.Add(NewName);
   end;

When the user enters a new name, it's actually added to the list.

There's just one (big !) problem: after ending the application and
restarting it, the new name is no longer part of the list.

I'm probably doing something wrong, but I can't find out what it is.
Any help ?

kind regards,

Ruud Schmeitz
Universiteit Maastricht

Re:ComboBox with incremental search ?


On Fri, 20 Feb 1998 17:14:06 +0100, Ruud Schmeitz

Quote
<R.Schme...@MEMIC.UNIMAAS.NL> wrote:
>Lina Scarpellini wrote:

>> Hi !
>> I'm quite new to Delphi programming.
>> I'd like to know how to allow the user to select a name in a DbComboBox but
>> at the same time permit him to enter a new name. For example, you type in
>> the first letters and if a correponding name already exists, the name
>> appears highlighted, and you simply select it. If not, then the user can
>> type it all in and it will be saved to the table.
>> Is there  already a component that does this job ? Do I have to code a
>> special procedure? Did I forget some properties of combo boxes or what ?

>> Any help appreciated !
>> Thanks in advance !
>> Lina

Do you wish to save it into a table, a TTable object?  or mearly add
it to the list within the combo  box?  If you mearly wish to add it
into the pull-down list on the combo box, you may add  the following
code:  It's Ruud's code that I modified, so it saves the list even
when you shut down the computer

in your main variable declarations you need to put the code :

var filename:string;

in your forms on create event you must put the following code:

begin
   filename:='c:\mydirectory\myfile.txt';
  dbcombobox1.LoadFromFile(FileName);   { load from file }
end;

...

Quote
>   procedure TForm1.Button1Click(Sender: TObject);
>   var
>     NewName : string;
>   begin
>     NewName := DBComboBox1.Text;
>     DBComboBox1.Items.Add(NewName);

      dbcombobox1.SaveToFile(filename);  

Quote
>   end;

>When the user enters a new name, it's actually added to the list.

>There's just one (big !) problem: after ending the application and
>restarting it, the new name is no longer part of the list.

>I'm probably doing something wrong, but I can't find out what it is.
>Any help ?

>kind regards,

>Ruud Schmeitz
>Universiteit Maastricht

When you design your program you have to click on the dbcombobox1 and
with the object inspector you gotta click on the "..." in the items
properity to bring up the string editor... enter the initial list of
items, then click on save as and save it as whatever file you put for
'c:\mydirectory\myfile.txt'

I hope this helps... oh and thanks for the idea... I was about to
write a component that would use another table to keep the list
items... your idea is  much more simple.  Thanks.  

--
Quote of the hour:
"Mine" - Tank Girl

-Jet

Re:ComboBox with incremental search ?


Quote
jet wrote:
> ...
> >   procedure TForm1.Button1Click(Sender: TObject);
> >   var

> >     NewName : string;
> >   begin

> >     NewName := DBComboBox1.Text;
> >     DBComboBox1.Items.Add(NewName);
>       dbcombobox1.SaveToFile(filename);   <<<====== (RS)
> >   end;
> > ...

It's better to use a conditional SaveToFile : write some code
to check first if the new name already exists on the list (to
prevent adding duplicate names to the list).

Quote
> ...
> I hope this helps... oh and thanks for the idea... I was about to
> write a component that would use another table to keep the list
> items... your idea is  much more simple.  Thanks.
> ...

You're welcome.
And don't forget to use the DBComboBox1 OnExit-event to check if
the user has actually added the new name to the list (of course
only if that name did not exist on the list before).

kind regards,

Ruud Schmeitz
Universiteit Maastricht

Other Threads