If code B you initially set the grid's RowCount to 5, but then you write some text into a cell of worksheet row 15 (i.e. grid row 16). This way the RowCount is automatically expanded to 16
You could remove the option aeData from the WorksheetGrid's AutoExpand property in order to avoid automatic expansion of the RowCount by writing data, but then you'll have an exception because the addressed row does not exist.