在ax2009中,只能对表字段进行筛选过滤。如果在窗体上显示的不是表字段而是一个display 方法。是不可能像字段一样过滤。如图
要想对display进行筛选过滤,必须在对应的窗体下面的grid里找到对应的display方法字段。然后重载context方法,并添加如下代码
public void context()
{ int selectedMenu; formrun fr;
Args ag; Name strtext;
querybuilddataSource qb1;
queryrun qr; query q;
PopupMenu menu = new PopupMenu(element.hWnd());
int a = menu.insertItem("根据字段过滤");
int b = menu.insertItem("根据所选子段过滤");
int c = menu.insertItem("取消过滤");
;
selectedMenu = menu.draw();
switch (selectedMenu)
{ case -1: //Filter by field
break;
case a:
ag = new args('SysformSearch');
fr = new formrun(ag);
fr.run();
fr.wait(); //Reading User entered value for filter process
strtext = fr.design().controlName('FindEdit').valueStr();
if(strtext)
{ //Creating a query for filter
q = RGD_StudentInfo_ds.query();
qb1 = q.dataSourceTable(tablenum(RGD_StudentInfo));
qb1 = qb1.addDataSource(TableNum(HRMCourseTable));
qb1.addLink(FieldNum(RGD_StudentInfo,hrmCourseId),FieldNum(HRMCourseTable,hrmCourseId));
qb1.addRange(FieldNum(HRMCourseTable,hrmCourseRoomId)).value(strtext);
RGD_StudentInfo_ds.query(q);
RGD_StudentInfo_ds.executeQuery();
}
break;
case b: // Filter By Selection
q = RGD_StudentInfo_ds.query();
qb1 = q.dataSourceTable(tablenum(RGD_StudentInfo));
qb1 = qb1.addDataSource(TableNum(HRMCourseTable));
qb1.addLink(FieldNum(RGD_StudentInfo,hrmCourseId),FieldNum(HRMCourseTable,hrmCourseId));
qb1.addRange(FieldNum(HRMCourseTable,hrmCourseRoomId)).value(disTest.valueStr());
RGD_StudentInfo_ds.query(q);
RGD_StudentInfo_ds.executeQuery();
break;
case c : // Remove Filter
q = new Query();
qb1 = q.addDataSource(tablenum(RGD_StudentInfo));
qb1.clearLinks();
qb1.clearRanges();
RGD_StudentInfo_ds.query(Q);
RGD_StudentInfo_ds.removeFilter();
break;
Default:
break;
}
添加完后得到界面如下: