I am trying to perform:
Form3.StringGrid1.Cells[0,Form3.StringGrid1.RowCount] := 'Hoofdstad';
after performing:
Onderdelen := Form3.StringGrid1.RowCount;
Form3.StringGrid1.RowCount := Onderdelen + 1;
It gives an error every time, it will say that I am trying to change the text of a cell that doesnt exist (yet). I am still very new to this language, I hope someone can help me out.
The
Cellsproperty uses 0-based indexing. The index of the first row is 0 and the index of the last row isRowCount-1. When you add a new row, theRowCountincreases, but the index of the last row is stillRowCount-1.So, when you are trying to use this:
Form3.StringGrid1.Cells[0,Form3.StringGrid1.RowCount] := 'Hoofdstad';You are going out of bounds, because
Form3.StringGrid1.RowCountis 1 too high. You need to use this instead:Alternatively, since
Onderdelenalready contains the proper index value: