Query Ranges for filter

I have a form which has a datasource containing fields 1) ID(string) 2)Name(string) 3)Amount(Real) 4) From year(int) 5) To year (int). i have taken two unbounded field for from year and toyear of combo box type and have written code for getting dropdown of year on init of form. now if i select this from year and to year and click filter button. it should filter my datasource year fields.

How can i do that??

Plz help.i tried writting code on selection change of unbound fields and call it on clicked but its not working…Kindly help.

Regards,

Kiran

What exactly do you need help with? Do you know how to use query ranges?

You said you want to execute the action on clicking a button, therefore you should override its clicked() method and call your logic from there.

thanks for replying.following are the code i have written:

public class FormRun extends ObjectRun

{

QueryBuildRange queryBuildRangeFrom, queryBuildRangeTo,qbr;

}

public void init()

{

int i,curyear;

;

super();

for(i= 0 ; i<=150; i++)

{

curyear = 1990 + i;

FromYear.insert(int2str(curyear),i);//combo box field

ToYear.insert(int2str(curyear),i);//combobox field

}

}

public void executeQuery()

{

//int vl,v2;

// str v3;

;

// qbr = //this.query().dataSourceName(‘GOD_GrossSalesTurnover’).addRange(fieldNum(GOD_GrossSalesTurnover, //MembershipNumber));

queryBuildRangeFrom = GOD_GrossSalesTurnover_DS.queryBuildDataSource().addRange(fieldNum(GOD_GrossSalesTurnover,FromYear));

queryBuildRangeTo = GOD_GrossSalesTurnover_DS.queryBuildDataSource().addRange(fieldNum(GOD_GrossSalesTurnover,ToYear));

queryBuildRangeFrom.value(queryValue(FromYear.selection()));

queryBuildRangeTo.value(queryValue(ToYear.selection()));

// v3 = any2str(CopyOfGOD_GrossSalesTurnover_MembershipNumber.valueStr());

// if(v3!="")

// {

qbr.value(queryValue(strFmt(v3)));

// }

super();

}

void clicked()

{

;

GOD_GrossSalesTurnover_ds.executeQuery();

super();

}

now wen i open the form i am not able to see the actual datasource records even before applying the filter.

Please look at what value you get from selection() - it returns int, so it’s the index, not the value of the combo box item.

Also, don’t add ranges every time when executeQuery() gets called - that would easily lead to adding ranges multiple times. You can use SysQuery::findOrCreateRange(), for example, to reuse the same ranges.