i want to make a button disabled if a datagrid is empty and it should be enabled when there is atleast 1 entry.the entries in the grid are made at runtime.I tried this
this is the button:
<mx:Button id="update" label="Update Contact" enabled="{isButtonEnabled()}"/>
and the function is defined as where dg_contact is the datagrid:
public function isButtonEnabled():Boolean
{
if(dg_contact.selectedIndex==-1)
{
return false;
}
else
{
return true;
}
}
where am i going wrong?
Your code doesn’t work because
isButtonEnabled()doesn’t get called whenselectedIndexchanges. You can useBindingUtilsto do that, but this can be done withoutBindingUtilsDataGridcan have items and yet have itsselectedIndexequal to -1. If you’re not bothered about if an item is selected or not, bind it to the length ofDataGrid‘sdataProviderIf you want button to be enabled only when something is selected, bind it to
selectedIndex