随笔 - 125  文章 - 1 评论 - 9 阅读 - 22万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

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

 

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

 

posted on   EEEEEEEEEEEEEEEEEEE  阅读(3480)  评论(1编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示