How to force saving records from a grid when clicking in a button

To do so override the method cliked of the button and add :
MyDataSource_ds.write();

void clicked()
{
boolean ret;
Qty Qty;
;

super();

if (ThyProjForcasTable.ProjCategoryType == Thyprojforecast::hour)
{
element.CheckQty(ForcostEmplTab, ProjForecastEmpl_DS.QtyRemains(), ProjForecastEmpl_DS.EmplCostAmount());
}
if (ThyProjForcasTable.ProjCategoryType == Thyprojforecast::sales)
{
element.CheckQty(ForCastSales, ForecastSales_DS.QtyRemains(), ForecastSales_DS.SalesCostAmount());
}
if (ThyProjForcasTable.ProjCategoryType == Thyprojforecast::cost)
{
element.CheckQty(ForCastCost, ProjForecastCost_DS.QtyRemains(), ProjForecastCost_DS.CostAmount() );
}

ThyProjForcasTable_ds.write();

}