Recent

Author Topic: combobox and autocomplete property [win32]  (Read 7041 times)

evel

  • Guest
combobox and autocomplete property [win32]
« on: April 08, 2005, 01:11:09 am »
hi,

comboBox component does not have autocomplete properties yet. Have anybody solution how to add manualy this properties ? or when this propertis will be added, or mayby someone have alternative function witch do that.

--
evel
email: athome<REMOVE>@poczta.fm

matthijs

  • Hero Member
  • *****
  • Posts: 537
combobox and autocomplete property [win32]
« Reply #1 on: April 08, 2005, 10:40:56 am »
You could use the OnChange event to mimick the autocomplete behaviour. Just set the text property in this event to the first item you find which start with the characters the user entered. Then select the characters which you filled in. use  SelStart and SelEnd.
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

evel

  • Guest
combobox and autocomplete property [win32]
« Reply #2 on: April 08, 2005, 03:46:15 pm »
thx matthijs :-)

I do this using onchange and onkeypress (for backspace) :

source :

procedure TForm1.ComboBox1Change(Sender: TObject);
var
i:integer;
str:string;
begin
  for i:=0 to combobox1.Items.Count-1 do
    if pos(combobox1.Text,combobox1.Items.Strings)>0 then
       begin
          str:=combobox1.Text;
          combobox1.Text:=combobox1.Items.Strings;
          combobox1.SelStart:=(length(str));
          combobox1.SelLength:=(length(combobox1.text));
          exit;
         end;
end;

procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
str:string;
begin
if (key=#8) and (combobox1.SelText<>'') then   { backspace key }
   begin
    str:=combobox1.text;
    delete(str,combobox1.SelStart+1,combobox1.SelLength);
    combobox1.Selstart:=0;
    combobox1.SelLength:=0;
    combobox1.text:=str;
    keybd_event(Ord(VK_END),0,0,0);
    keybd_event(Ord(VK_END),0,KEYEVENTF_KEYUP,0);
   end;
end;

evel

  • Guest
combobox and autocomplete property [win32]
« Reply #3 on: April 08, 2005, 04:30:35 pm »
sorry 2 bugs - small update for onchange procedure

procedure TForm1.ComboBox1Change(Sender: TObject);
var
i:integer;
str:string;
begin

  for i:=0 to combobox1.Items.Count-1 do
        if pos(upstring(combobox1.Text),upstring(copy(combobox1.Items.Strings,1,length(combobox1.Text))))>0 then
       begin
          str:=combobox1.Text;
          combobox1.Text:=combobox1.Items.Strings;
          combobox1.SelStart:=(length(str));
          combobox1.SelLength:=(length(combobox1.text));
          exit;
         end;
       combobox1.ItemIndex:=-1;
end;

 

TinyPortal © 2005-2018