[收藏资料]CXGRID过滤

[湖北]-沉湖(408026213)  15:04:08
function SearchTextIncxGrid(aText: string; aGrid: TcxGridDBTableView; QueryField: string): Boolean;
var
  I, IDField, IDJianPinField, IDQuanPinField: Integer;
  GetAText: string;
begin
  GetAText := UpperCase(Trim(aText));
  if not SameText(Trim(GetAText), '') then
  begin
    aGrid.DataController.Filter.clear;
  end;

  if aGrid.ColumnCount > 3 then
  begin
    with aGrid do
    begin
      for I := 0 to ColumnCount - 1 do
      begin
        if Columns[I].DataBinding.FieldName = QueryField then
        begin
          IDField := I;
        end;
        if Columns[I].DataBinding.FieldName = 'SPY' then
        begin
          IDJianPinField := I;
        end;
        if Columns[I].DataBinding.FieldName = 'LPY' then
        begin
          IDQuanPinField := I;
        end;
      end;
      DataController.Filter.BeginUpdate;
      try
        with DataController.Filter do
        begin
          Root.Clear;
          Root.BoolOperatorKind := fboOr;
          Root.AddItem(Columns[IDField], foLike, '%' + GetAText + '%', '''%' + GetAText + '%''');
          Root.AddItem(Columns[IDField], foEqual, GetAText, '' + GetAText + '');
          if IDQuanPinField > 0 then
          begin
            Root.AddItem(Columns[IDQuanPinField], foLike, '%' + GetAText + '%', '''%' + GetAText + '%''');
          end;
          if IDJianPinField > 0 then
          begin
            Root.AddItem(Columns[IDJianPinField], foLike, '%' + GetAText + '%', '''%' + GetAText + '%''');
          end;
        end;
        DataController.Filter.Active := True;
      finally
        DataController.Filter.EndUpdate;
      end;
    end;
  end;
  result := True;
end;

posted @ 2010-07-05 15:12  周黔  阅读(955)  评论(0编辑  收藏  举报