Selecting current cell/row in a Strgrid in Delphi?

Hi

Looking to select the contents of the currently selected cell (as in you click a cell, and I want an onclick on a button to modify its contents. Basically looking for the string grid equivelant of dataset.fieldvalues[fieldname]...

Cheers
TTRMWAsked:
Who is Participating?
 
SteveBayConnect With a Mentor Commented:
Not quite.
It would look more like this

procedure TForm1.Button1Click(Sender: TObject);
begin
     Grid1.Cells[Grid1.Selection.Left,Grid1.Selection.Top] := 'Way New Value';
end;

Open in new window

0
 
SteveBayCommented:
Do you mean something like this?
OnSelectCell event:
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
begin
     TStringGrid(Sender).Cells[ACol,ARow] := 'New Value';
end;

Open in new window

0
 
TTRMWAuthor Commented:
I'm thinking that will work. Possibly if I set variables to the col/row reference of the cell and use them for modification on the onclick?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
TTRMWAuthor Commented:
Actually, how would I go about doing that?

I would like to change the currently selected record on a separate event - all I can think of is sending cells[aCol,aRow] to different variables? I guess aCol and aRow refer to current grid reference, but are they globals?
0
 
SteveBayCommented:
I see.
Then set Options>goRangeSelect = False; and use Grid1.Selection to find the currently selected cell.
0
 
TTRMWAuthor Commented:
So the onclick would be grid1.selection := 'new value'?
0
 
TTRMWAuthor Commented:
Brilliant - cheers!
0
All Courses

From novice to tech pro — start learning today.