2008. május 6., kedd

How to create a TComboBox with incremental search capabilities


Is there a way to let a TComboBox do incremental search in its drop down list? Currently it uses only the first letter so if multiple items start with the same letter it's not very useful.


Create a new Combo inherited from class(TcustomComboBox) and change the Change Event to the following few lines:


procedure Change; override;

  procedure TExtComboBox.Change;
    str: string;
    Index: Integer;
    inherited Change;
    str := Text;
    if (FLastKey = VK_DELETE) or (FLastKey = VK_BACK) then
      SelStart := Length(str);
      SelLength := 0;
    {try to find the closest matching item}
    Index := Perform(CB_FINDSTRING, -1, LPARAM(str));
    if Index <> CB_ERR then
      ItemIndex := Index;
      SelStart := Length(str);
      SelLength := Length(Items[Index]) - SelStart;
      Text := str;
    {call standard event}
    if Assigned(FOnChange) then

Nincsenek megjegyzések:

Megjegyzés küldése