1. 程式人生 > >cxGrid FilterRow 添加左模糊查詢,實現 %ABC%

cxGrid FilterRow 添加左模糊查詢,實現 %ABC%

onchange div 需要 custom hang 參考 for view http

參考了 踏雪無痕 的資料 :http://blog.csdn.net/zengcong2013/article/details/12343171

由於 cxGrid 中,使用較多是 cxGridDBTableView 因此調整了一下,更方便 Ctrl V

--------------------------------------------------------------------------------------------------------

cxGrid 的FilterRow 默認是右匹配模糊查詢,即 ABC%

因此需要添加代碼,實現 %ABC% 左右模糊查詢

1、主要處理的過程為

procedure SetCustomFilterRow(cxGridTableView: TcxGridDBTableView);
var
I: Integer;
S: string;
begin
with cxGridTableView, ViewData do
begin
if FilterRow.Focused then
begin
for I := 0 to ColumnCount - 1 do
begin
S := VarToStr(FilterRow.Values[I]);
if (Length(S)> 0) and (S[1] <> ‘%‘) then
FilterRow.Values[I] := ‘%‘ + S;
end;
end;
end;
end;

2、在 cxGridDBTableView1的 Event—>DataTontroller—>Filter—>OnChanged

添加代碼

procedure TForm1.cxGridDBTableView1DataControllerFilterChanged(Sender: TObject);
begin
SetCustomFilterRow(cxGridDBTableView1);
end;

cxGrid FilterRow 添加左模糊查詢,實現 %ABC%