2014-04-19 4 views
1

여기 목록 상자에서 필터를 검색하는 동안 문제가 발생했습니다. 실제로 TEdit 컨트롤의 텍스트와 관련된 모든 항목을 선택하고 싶습니다. 여러 항목이 일치하면 여러 항목을 선택해야합니다.델파이의 목록 상자 검색 필터

그런데 이미 multiselect 속성을 True로 선택했습니다.

procedure TForm1.Button3Click(Sender: TObject); 
var 
    I: Integer; 
begin 
    if OpenDialog1.Execute then 
    for I := 0 to OpenDialog1.Files.Count - 1 do 
     ListBox1.Items.Add(ExtractFileName(OpenDialog1.Files.Strings[i])); 
end; 

검색 필터 코드 :

여기 내 코드입니다

procedure TForm1.Edit1Change(Sender: TObject); 
var 
    I: Integer; 
begin 
    for I := 0 to ListBox1.Items.Count - 1 do 
    ListBox1.Selected[i] := False; 

    for I := 0 to ListBox1.Items.Count - 1 do 
    if ListBox1.Items.Strings[i].Contains(Edit1.Text) then 
     ListBox1.Selected[i] := True; 
end; 

이 코드는 잘 작동하지만 난 경우를 무시하고 검색 할 수 없습니다 때 문제입니다. 검색은 대소 문자를 구분하므로 대소 문자를 구분하지 않아야합니다.

+0

보통 언어가 원하는 경우 모든 텍스트를 변환 할 수있는 옵션이 있습니다. 이렇게하면 쿼리 검색과 텍스트를 검색 할 때 대/소문자를 구분하지 않습니다. (나는 delphy를 모른다. 그래서 정확한 함수를 말할 수는 없지만 약간의 튜토리얼이나 문서를 보자. – Llopis

+1

['This way'] (http://pastebin.com/6mSEigdk). @Llopis 또는 문자열의 대/소문자를 구분하지 않고 검색 할 수있는 함수가있을 수 있습니다. 델파이에는 [ContainsText'] (http://docwiki.embarcadero.com/Libraries/XE4/en/System.StrUtils.ContainsText) 함수가 있습니다. – TLama

+0

@TLama : 코드가 작동했습니다. System.StrUtils.ContainsText.dcu가 존재하지 않는다는 오류를 보여주기 때문에 System.StrUtils.ContainsText 대신 System.StrUtils를 사용하여 대체해야합니다. 감사합니다. –

답변

1

TLama가 게시 한 코드를 사용하여 문제가 해결되었습니다. 고마워. 여기

코드가 수정 될 수 있습니다 :

uses 
    System.StrUtils; 

procedure TForm1.Edit1Change(Sender: TObject); 
var 
    I: Integer; 
begin 
    ListBox1.Items.BeginUpdate; 
    try 
    for I := 0 to ListBox1.Items.Count - 1 do 
     ListBox1.Selected[I] := ContainsText(ListBox1.Items[I], Edit1.Text); 
    finally 
    ListBox1.Items.EndUpdate; 
    end; 
end;