Forum Discussion
4 Replies
- KB1
Champion Level 2
In TestComplete, you can access the values of the cells in a StringGrid control by using the Cells property of the StringGrid object. The Cells property is a two-dimensional array of strings, where the first dimension represents the row index and the second dimension represents the column index.
For example, to access the value of the cell at row 3 and column 2, you can use the following code:
var CellValue: string; begin CellValue := StringGrid1.Cells[2, 3]; end;
You can also use a loop to iterate through all cells in the grid and access their values. For example:
var i, j: Integer; begin for i := 0 to StringGrid1.RowCount - 1 do for j := 0 to StringGrid1.ColCount - 1 do Log.Message(StringGrid1.Cells[j, i]); end;
This will log the value of each cell in the grid to the log window.
I hope this helps! Let me know if you have any questions.
- lalit_singhContributor
Hey;
Thanks for the solution provided , it works partially for me and I am able to access the caption of the grid
but the values are getting shown as blank
Am I missing something- KB1
Champion Level 2
It's possible that the values in the cells of the StringGrid are not being displayed because the cells are not being set to contain any values. In order to display a value in a cell, you need to set the value of the cell using the Cells property.
For example:
StringGrid1.Cells[2, 3] := 'Hello, World!';
This will set the value of the cell at row 3 and column 2 to "Hello, World!".
If you are trying to access the values of cells that were already set by some other process, make sure that you are using the correct row and column indices. It's also possible that the cells are empty because the StringGrid has not been populated with any data.