PDA

View Full Version : سوال: اصلاح Auto Complete



alenlion2
سه شنبه 06 دی 1390, 18:22 عصر
دوستان سلام
من خیلی دنبالش گشتم چیزی پیدا نکردم. امیدوارم سوالم تکراری نباشه.
مشکل من اینه که بعد از فعال کردن Auto Complete در کامپوننت combobox اگر 2 آیتم داشته باشیم
مثلا یکی 125 و دیگری 1252
با تایپ 125 combobox به شما 1252 رو پیشنهاد می ده و امکان انتخاب 125 با تابپ وجود نداره
کسی می دونه این مشکل رو چطوری باید حل کنم

BORHAN TEC
سه شنبه 06 دی 1390, 21:17 عصر
خاصیت Sorted رو به true تغییر دهید.

alenlion2
چهارشنبه 07 دی 1390, 12:27 عصر
نمی تونم این کارو بکنم چون ترتیبی که مد نظرمه باید حفظ بشه چطوری میشه جستجوی combobox رو تغییر داد؟؟؟

MohsenB
شنبه 10 دی 1390, 00:38 صبح
سلام

خودتون براش طراحی کنید

gogolo
یک شنبه 11 دی 1390, 12:37 عصر
سلام
انشاله این کد مشکلدون را حل کنه
شاد باشید

var
Form1: TForm1;
lKey: Word;
implementation
{$R *.dfm}
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
lKey := Key;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
var
Srch,minL,res: string;
minlx,ix,i,l: Integer;
begin
Srch := combobox1.Text;
if lKey = $08 then
begin
lKey := 0;
Exit;
end;
lKey := 0;
res:=(ComboBox1.Items.Strings[combobox1.Perform(CB_FINDSTRING, -1, Longint(PChar(Srch)))]);
for i:=0 to ComboBox1.Items.Count-1 do
begin
if Length(res)>length(ComboBox1.Items.Strings[combobox1.Perform(CB_FINDSTRING, i, Longint(PChar(Srch)))]) then
begin
res:=ComboBox1.Items.Strings[combobox1.Perform(CB_FINDSTRING, i, Longint(PChar(Srch)))];
end;
end;
ix:=(ComboBox1.Items.IndexOf(res));
if ix > CB_ERR then
begin
combobox1.ItemIndex :=ix ;
combobox1.SelStart := Length(Srch);
combobox1.SelLength := (Length(combobox1.Text) - Length(Srch));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.AutoComplete:=false;
end;