1

I have some difficulties in entering some data into TGrid Cells, can someone give me some code example with commentary on how to insert data into a TGrid cell? To be more precise in C++ Builder when I'm using a StringGrid I can use

StringGrid1->Cells[1][0] = "Hello world";

which will insert in the cell of the second column of the first row the "hello world" message. How can I do the same with TGrid? And how can I use TCheckColumn? I have many diffulties because I cannot find any good documentation.
I'm looking but there is no guide on this anywhere.

Laz22434
  • 373
  • 1
  • 12
  • http://docwiki.embarcadero.com/CodeExamples/Berlin/en/TGrid_(Delphi) – sddk Apr 29 '16 at 06:16
  • Possible duplicate of [Firemonkey: TGrid usage on Embarcadero C++ Builder XE3](http://stackoverflow.com/questions/15543698/firemonkey-tgrid-usage-on-embarcadero-c-builder-xe3) – Tom Brunberg Apr 29 '16 at 09:04
  • 1
    This helped me a lot [MonkeyStyler](http://monkeystyler.com/guide/TGrid) – Freddie Bell May 07 '16 at 16:18

1 Answers1

0

TL;DR:
You need to store the data in your own data structure, and pass it to the displayed grid via the OnGetValue event.


I found the answer in the link to MonkeyStyler provided by @nolaspeaker in the comments.

TGrid does not store any data internally.

You need to store the data yourself. When a cell in your grid is displayed, the OnGetValue(Sender: TObject; const Col, Row: Integer; var Value: TValue) event is fired.

It is up to you to implement an event handler for this, and return the data for the given cell.

For example, suppose you have a very simple grid that only shows "hello" in every cell of the first column and "world" in every cell of the second column.
Your OnGetValue event would look like this:

procedure MyOnGetValueHandler(Sender: TObject; const Col, Row: Integer; var Value: TValue);
begin
  if Col = 0 then
    Value := 'hello'
 else 
 if Col = 1 then
    Value := 'world';
end;