How to disable button with grid is not empty condition?

hello guys

I have form called TmpPurchReqTable form and in my form they want me to inactive of Purpose button when My form’s gird is empty.Normally I have a select button and it brings filtered data when I click it,but If I dont click my form’s grid is empty.

How can I can check the grid’s condition to disable a button?

this is my purpose button method:

while select TmpPurchReq where AxsTmpPurchReq.AxsAddProp == NoYes::Yes
{

_PurchPropItemTemplate.clear();
_PurchPropItemTemplate.initFromtmpPurchReq(TmpPurchReq);
_PurchPropItemTemplate.AxsPurchPropID = _PurchPropTable.PurchPropID;
_PurchRequestLine = AxsTmpPurchReq.PurchRequestline(true);
_PurchRequestLine.AxsPurchPropID = _PurchPropTable.PurchPropID;
_PurchRequestLine.AxsPropStatus = PropStatus::Approval;
_PurchRequestLine.BuzItemDesc = TmpPurchReq.BuzItemDesc;

_PurchRequestLine.update();
_PurchPropItemTemplate.insert();
}

ttscommit;

info(strfmt(’%1 ’ + ‘@AXS3406’,_PurchPropTable.PurchPropID));
ttsbegin;

delete_from TmpPurchReq;

ttscommit;

public int active()
{
TmpPurchReq _TmpPurchReq;

int ret;
;

ret = super();
if(_AxsTmpPurchReq.axsPurchRequestID)
{
button.enabled(true);
ELEMENT.setdata();
}
else
{
button.enabled(false);
}
return ret;
}
I wrote somethingl like that for diasbale the the button ,but of course Its not working

My froms is tmp form and I dont know how to check grid is empty of not.Grid comes with value only I push the se select button and in select button there is code to fill the temp form
could you guys help me please

Have you tried by setting NeedsRecord property on button to Yes?

I checked the button’s properties but could not see it.

Property.PNG

it is ax 2009,Maybe there is no noorecords on ax 2009?

That property exists in AX 2012. You have tagged your post under AX 2012.
There is no such property in AX 2009, you have to write code.
In active method of the data source,
button.enabled(dataSource.RecId);

Isorry about the wrong tagged,I did not check the ax version at first.

That’s fine. Have you tired with the code in active method?

I tried it ,my form 's datasource table is temp table.so when I first open its empty if I pusht the select button its getting value by query from another table but they want before pushing the select button they want to dis able to purpose button.cuz if the forms empty its creating empty requestlines they dont want this.so I am trying to diasable the purpose button if the temp table’s form is empty

button.enabled(dataSource.RecId); ı tried this ,but did not work
public int active()
{

int ret;
;

ret = super();

Purpose.enabled(TmpPurchReq.RecId);

return ret;
}

I figured out I wrote your code select button it worked