首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

cxGrid 可以直接打开 flt 过滤资料吗

2013-09-08 
cxGrid 可以直接打开 flt 过滤文件吗?cxGrid 的过滤功能确实好用,可以将过滤条件保存为一个文件,下次再查

cxGrid 可以直接打开 flt 过滤文件吗?
cxGrid 的过滤功能确实好用,可以将过滤条件保存为一个文件,下次再查询相同条件时,无需重新设定条件,只需开保存过的文件即可,但必须先打开过滤界面,然后再打开条件文件才可以.
我现在想实现一个功能,就是把保存过的条件文件(.flt)关联到一个Listbox里,只需用点一下该文件,就立即过滤出该文件保存的过滤条件,无需经过过滤界面,不知是否可行?
[解决办法]
1 把这三个文件移到你的程序目录:
  cxFilterControlDialog.pas, cxFilterControlDialog.dfm, cxGridCustomTableView.pas;
2 修改cxFilterControlDialog.pas


// Added by Simon 2013/9/4 10:05:13
//声明 全局
function cxInternalExecuteFilterControlDialogEx(ALink: TComponent; const AFileName : string): Boolean;
//实现
function cxInternalExecuteFilterControlDialogEx(ALink: TComponent; const AFileName : string): Boolean;
var
  AForm: TfmFilterControlDialog;
  AIntf: IcxFilterControlDialog;
begin
  AForm := TfmFilterControlDialog.Create(Application);
  with AForm do
  try
    FFilterControl := TcxFilterControl.Create(nil);

    if Supports(TObject(FFilterControl), IcxFilterControlDialog, AIntf) then
      AIntf.SetDialogLinkComponent(ALink);
    AIntf := nil; //force to clear interface

    FilterControl.LoadFromFile(AFileName);
    SetTitle(AFileName);

    FilterControl.ApplyFilter;
    Result := True;
  finally
    FFilterControl.Free;
    Free;
  end;
end;


修改cxGridCustomTableView.pas

//TcxCustomGridTableFiltering public 声明
procedure LoadFilterFile(const AFileName : string);

//实现
procedure TcxCustomGridTableFiltering.LoadFilterFile(const AFileName : string);
begin
  if not GridView.DoFilterCustomization then
     cxInternalExecuteFilterControlDialogEx(GridView, AFileName);
end;


界面调用
  
//tv1 : TcxGridBandedTableView


tv1.DataController.Filter.Active := True;
  tv1.Filtering.LoadFilterFile('c:\2.flt');

热点排行