DevExpress控件TExtLookupComboBox实现多列模糊匹配输入的方法
本方案不需要修改控件源码,是完美解决支持多列模糊匹配快速输入的最佳方案!!
本实例应用于 CXGRID
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控件实现,方法与上述雷同!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了