AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Autocomplete bei ComboBox

Ein Thema von Sidores · begonnen am 15. Apr 2004 · letzter Beitrag vom 15. Apr 2004
Antwort Antwort
Sidores

Registriert seit: 17. Sep 2003
Ort: Oldenburg
107 Beiträge
 
Delphi 7 Professional
 
#1

Autocomplete bei ComboBox

  Alt 15. Apr 2004, 16:01
hi,

wie kann man die autocomplete funktion der ComboBox manuell aufrufen.
(meine halt das wie als wenn man auf den Pfeil drückt)
Übergangsweise fahre ich die ComboBox aus und wieder ein
=> hat den gleichen Effekt, ist aber Optisch nicht sehr ansprechend und sehr langsam.

Danke
  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#2

Re: Autocomplete bei ComboBox

  Alt 15. Apr 2004, 16:40
Hi,


Meinst du so was?

Delphi-Quellcode:
procedure TForm1.ComboBox1Change(Sender: TObject);
var
  oldpos: Integer;
  item: Integer;
begin
  with Sender as TComboBox do begin
    oldpos := SelStart;
    item := Perform(CB_FINDSTRING, -1,
                     lParam(PChar(Text)));
    if item >= 0 then
    begin
      OnChange := nil;
      text := Items[item];
      SelStart := oldpos;
      SelLength := GetTextLen - SelStart;
      OnChange := ComboBox1Change;
    end;
  end;
end;

procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
  oldlen: Integer;
begin
  if Key = #8 then
    with Sender as TComboBox do
    begin
      oldlen := SelLength;
      if SelStart > 0 then
      begin
        SelStart := SelStart - 1;
        SelLength := oldlen + 1;
      end;
    end;
end;
Thomas
  Mit Zitat antworten Zitat
Benutzerbild von eddy
eddy

Registriert seit: 3. Jan 2003
Ort: Sachsen
573 Beiträge
 
Delphi 5 Professional
 
#3

Re: Autocomplete bei ComboBox

  Alt 15. Apr 2004, 16:59
Hallo Sidores,

ich nutze folgende Komponente:

Code:
unit ComboBoxAF;  //ComboBox AutoFill

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TComboBoxAF = class(TComboBox)
  ****ate
    { ****ate-Deklarationen }
    FAutoFill : Boolean;
    function GetAutoFill : Boolean;
    procedure SetAutoFill(value : Boolean);
  protected
    { Protected-Deklarationen }
    procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
                                                  ComboProc: Pointer); override;

  public
    { Public-Deklarationen }
    constructor Create(aOwner: TComponent); override;
    Destructor Destroy; override;
  published
    { Published-Deklarationen }
    property AutoFill : Boolean read GetAutoFill write SetAutoFill;
  end;

procedure Register;

implementation

procedure TComboBoxAF.ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
                                                            ComboProc: Pointer);
var
  I: Integer;
  s: String;
begin
  inherited ComboWndProc(Message, ComboWnd, ComboProc);
  if not FAutoFill then Exit;
  if Message.Msg = WM_CHAR then begin
    if TWMChar(Message).CharCode in [$20..$7F] then begin
      s := Text;
      I := SendMessage(Handle, CB_FINDSTRING, -1, LongInt(PChar(s)));
      if I >= 0 then begin
        Text := Items.Strings[I];
        SelStart := Length(s);
        SelLength := Length(Text) - Length(s);
      end;
    end;
  end;
end;


function TComboBoxAF.GetAutoFill : Boolean;
begin
  Result := FAutoFill;
end;

procedure TComboBoxAF.SetAutoFill(value : Boolean);
begin
  FAutoFill := value;
end;

constructor TComboBoxAF.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  FAutoFill := true;
  Sorted := true;
end;

Destructor TComboBoxAF.Destroy;
Begin
  inherited Destroy;
End;

procedure Register;
begin
  RegisterComponents('Beispiele', [TComboBoxAF]); //
end;

end.
mfg
eddy
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:23 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz