1

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

Marcell
  • 91
  • 1
  • 1
  • 8

1 Answers1

3

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];
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770