Thema: Delphi Combobox mit suche

Einzelnen Beitrag anzeigen

Tyrael Y.

Registriert seit: 28. Jul 2003
Ort: Stuttgart
1.093 Beiträge
 
Delphi 2007 Professional
 
#6

Re: Combobox mit suche

  Alt 26. Feb 2008, 09:26
Direkt konnte ich mit dieser Komponente nix anfangen.

Ich habe es leicht modifiziert und jetzt reagiert ist so, wie ich es wollte.
Bisschen umständlich ist die Handhabung, da man die zweite Liste von Hand füllen muss. Für jedes Item, das man einfügt muss man beachten, das der angezeigte string auch in die zweite Liste eingefügt werden muss. Dies findet nicht automatsich statt.

Hier mal die modifizierte Stelle, das auskommentierte ist der Originalcode

Delphi-Quellcode:
    //if InputLength > 0 then
    //begin
      // Add the items that should be in the dropdownlist to a temporary
      // stringlist, this way you know whether there actually are items
      // to appear in the dropdownlist before manipulating the combobox.
      TempList := TStringList.Create;
      try
        // FDropDownListCandidates is the list that contains all potential items
        // for the dropdownlist.
        for i := 0 to FDropDownListCandidates.Count - 1 do
        begin
          // Add the FDropDownListCandidates to the TempList that are
          // same as strInput:

          //if UpperCase(Copy(FDropDownListCandidates[i], 1, InputLength)) =
          // UpperCase(strInput) then
          if strInput = #0 then
          begin
            TempList.Add(FDropDownListCandidates[i]);
          end
          else
          if Pos(UpperCase(Trim(strInput)), UpperCase(FDropDownListCandidates[i])) > 0 then
          begin
            TempList.Add(FDropDownListCandidates[i]);
          end;
        end;
        if TempList.Count > 0 then
        begin
          // There are items to be displayed in the dropdownlist.
          // First add dummy items before making DroppedDown = True
          // because the DropDownCount can not be increased once it is
          // dropped down:
          for i := 1 to DropDownCount do
          begin
            Items.Add('');
          end;
          DroppedDown := True;
          // Remove dummy items:
          Items.Clear;
          // Copy TempList to Items:
          Items := TempList;
        end
        else // Templist.Count = 0, don't show the DropDownList:
          DroppedDown := False;
      finally
        TempList.Free;
      end;
    //end;
    //else // Length(strInput) = 0, no input, don't show the DropDownList:
    // DroppedDown := False;
Levent Yildirim
Erzeugung von Icons aus Bildern:IconLev
  Mit Zitat antworten Zitat