DevExpress控件TExtLookupComboBox實現多列模糊匹配輸入的方法


本方案不需要修改控件源碼,是完美解決支持多列模糊匹配快速輸入的最佳方案!!

 

1、把列的Properties屬性設置為ExtLookupComboBox。

Properties.IncrementalFiltering := False;
Properties.CaseSensitiveSearch := False; 
Properties.DropDownListStyle := lsEditList;

當然,接着要完成設置Properties.View,Properties.KeyFieldNames和Properties.ListFieldItem。

  // 本案例的列是:cxGridDBTableView1VENDOR_ID: TcxGridDBColumn;綁定服務商ID自動。

2、Properties.OnChange事件代碼:

procedure TFormcxLookupCombox.cxGridDBTableView1VENDOR_IDPropertiesChange(Sender: TObject);

var
  iCol: Integer;
  vInputText: String;
begin
  // 注:cxGridDBTableView1VENDOR_ID: TcxGridDBColumn;
  (Sender as TcxExtLookupComboBox).Properties.IncrementalSearch := False; //必需
  (Sender as TcxExtLookupComboBox).Properties.CaseInsensitive := True;    //必需
  //(Sender as TcxExtLookupComboBox).Properties.IncrementalFiltering := False;//設計期在Properties中設置好.
  //(Sender as TcxExtLookupComboBox).Properties.CaseSensitiveSearch := False; //設計期在Properties中設置好.
  //(Sender as TcxExtLookupComboBox).Properties.DropDownListStyle := lsEditList;//設計期在Properties中設置好
  vInputText := (Sender as TcxExtLookupComboBox).EditText;
  // with (cxGrid1DBTableView1VENDOR_ID.Properties as TcxExtLookupComboBoxProperties) do
  with (Sender as TcxExtLookupComboBox).Properties do    // 改為通用寫法.
  begin
    View.DataController.Filter.Options := [fcoCaseInsensitive];
    View.DataController.Filter.Clear;
    View.DataController.Filter.Root.Clear;
    // view中所有可視列都用於模糊檢索.
    for iCol := 0 to View.VisibleItemCount - 1 do
    begin
      if iCol > 0 then View.DataController.Filter.Root.BoolOperatorKind := fboOR;
      View.DataController.Filter.Root.AddItem(View.VisibleItems[iCol], foLike,
       '%' + vInputText + '%', '%' + vInputText + '%');
    end;
    View.DataController.Filter.Active := True;
  end;
end;

3、Properties.OnCloseUp事件代碼:
procedure TFormcxLookupCombox.cxGridDBTableView1VENDOR_IDPropertiesCloseUp(Sender: TObject);
begin
  (Sender as TcxExtLookupComboBox).Properties.View.DataController.Filter.Clear;

end;

如果不是在cxGrid的列中編輯數據,則可以用TcxDBExtLookupComboBox控件實現,方法與上述雷同!

 

轉自:http://blog.csdn.net/qq56430204/article/details/52199007

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM