How to read TStringGrid values and assign them to TEdits

96 views Asked by At

I am trying to implement a way to select a person's name from a TStringGrid that has values in two rows with two columns. These rows represent names of people and their respective ages. Once a name is selected by clicking on it, I want to fill two TEdit fields with the name and age that I selected.

I have been struggling with this and I can only get the entire row as one string, but I need the name and age as separate strings.

I have attached a screenshot to give an idea of what I am trying to accomplish. Thank you for any help.

TStringGrid Screenshot

1

There are 1 answers

0
Remy Lebeau On

Use the TStringGrid.Cells property to read the individual columns, and use the TStringGrid.Row property to know which row is selected.

var row: integer;
...
row := StringGrid1.Row;
Edit1.Text := StringGrid1.Cells[0,row];
Edit2.Text := StringGrid1.Cells[1,row];