[Delphi] 퀀텀그리드 [DevExpress QuantumGrid] 데이터 문자 검색 기능

퀀텀그리드(DevExpress QuantumGrid)에서 데이터에서 문자 검색 기능

FindRecordIndexByText 메서드 대해서는 문자열 지원 합니다.

검색기능

 

FindRecordIndexByText 메서드 설명

 

해당 레코드를 DeleteRecord 삭제 기능에서 사용되는 예시 입니다.

procedure TForm1.Button1Click(Sender: TObject);
Var
  iRow : Integer;
begin
  iRow :=  cxGrid1DBTableView1.DataController.FindRecordIndexByText(0 , 0 ,'Rushmac' ,False ,True ,True);
  if iRow >-1  then
    cxGrid1DBTableView1.DataController.DeleteRecord(iRow);   // 찾은 레코드 삭제
  
  // **FindRecordIndexByText 메서스 설명 **
  // FindRecordIndexByText(찾을시작위치,  
  //                      Index 위치, 
  //                      찾을문자값, 
  //                      [True(일부 찾기),False(문자열이 완전히 동일)], 
  //                      [True(시작위치 부터 아래로 찾다가 없으면 다시 처음부터 검색),False(아래 또는 위로 찾다가 자기 자신을 리턴), 
  //                      [True(아래로 찾는다), False(위로 찾는다))
  //                        
end;

 

 

FindRecordIndexByText 단점 중 중간 문자열 검색 안되는 현상
의문점이 생기는 부분 대해서는 "ABC1234" 문자열에서 "BC1"  또는 "123"와 같은 부분 문자열 지원 하지 않는 문제가 생길 수 있습니다.  

"ABC1234"의 "ABC"와 같은 시작 부분 문자열만 FindRecordIndexByText 메서드만 검색하기 때문에 이런 경우에는 레코드를 반복으로  검색할 수 있습니다.

procedure TForm1.Button1Click(Sender: TObject);
var
  I, ARecordIndex: Integer;
begin
  for I := 0 to cxGrid1DBTableView1.DataController.FilteredRecordCount - 1 do
  begin
    ARecordIndex := cxGrid1DBTableView1.DataController.FilteredRecordIndex[I];
    if (Pos('Rushmac', cxGrid1DBTableView1.DataController.Values[ARecordIndex, cxGrid1DBTableView1Name.Index]) <> 0) then
      cxGrid1DBTableView1.DataController.FocusedRecordIndex := ARecordIndex;
  end;
  cxGrid1.SetFocus;
end;

 

마무리

FindRecordIndexByText 메서스 통해 원하는 레코드 위치를 찾을 수 있지만, 단점 처럼 중간 문자열 찾을 경우에는 할 수없이  For문으로 반복 작업이지만, 레코드가 적당한 크기 일 경우에는 큰 문제 없을 것라고 생각 합니다. 

반응형

이 글을 공유하기

댓글