How can I select the last row from the grid

Hello!
I solved my probleme:
mygrid.cells(mygrid.getRowId(i),6).setValue(’<a href=’<?=BASEURL?>managing_bustrip_busses/?pbt=’+busTripID+’’><?=LBL_ALOCATE?></a>’);

Now I have another one:
How can I select the last row from the grid, I tried:
mygrid.loadXML(…);
mygrid.setSelectedRow(mygrid.getRowsNum()-1);
Thanks

The loading is async. , you must to catch moment when data will be loaded in grid to call row related methods.
It can be done by onXLE event or by second parameter of loadXML

mygrid.loadXML(url,function(){
mygrid.selectRow(mygrid.getRowsNum()-1);
});