Topic: Addressing a TableGrid

Greetings,

I have a TableGrid on a form and I would like to grab the value of the first field in the first row... what is the proper
reference to grab that value?


Col1,  Col2,   Col3
xxx      yyy        zzz


I want to access  the "xxx", can someone please give me a example syntax.

Regards,
Keith

Re: Addressing a TableGrid

kweatherhead wrote:

Greetings,

I have a TableGrid on a form and I would like to grab the value of the first field in the first row... what is the proper
reference to grab that value?


Col1,  Col2,   Col3
xxx      yyy        zzz


I want to access  the "xxx", can someone please give me a example syntax.

Regards,
Keith

if Form1.TableGrid1.RowCount > 0 then begin
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsString);
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsFloat);
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsInteger);
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsDateTime); 
    ShowMessage(Form1.TableGrid1.Cells[0,0]); // string
end; 
brian

Re: Addressing a TableGrid

Brian,

Thanx for the reply !!

I am using ver 6.5

ShowMessage(frmLstClients.TableGrid1.Cell[0.0]);  // this gives me: Not enough actual parameters

ShowMessage(frmLstClients.TableGrid1.Cells[0.0]); ;; gives me:  the same error

if frmLstClients.tablegrid1.cell[0.0].AsString = ' Add A New Client'  then frmAddNewClient.show;

as does the above in the way I was originally trying to use it, whereas

if frmLstClients.tablegrid1.cells[0.0].AsString = ' Add A New Client'  then frmAddNewClient.show;
// says Strings do not have properties or methods

any ideas?

Thanx,
Keith

Re: Addressing a TableGrid

kweatherhead wrote:

Brian,

Thanx for the reply !!

I am using ver 6.5

ShowMessage(frmLstClients.TableGrid1.Cell[0.0]);  // this gives me: Not enough actual parameters

ShowMessage(frmLstClients.TableGrid1.Cells[0.0]); ;; gives me:  the same error

if frmLstClients.tablegrid1.cell[0.0].AsString = ' Add A New Client'  then frmAddNewClient.show;

as does the above in the way I was originally trying to use it, whereas

if frmLstClients.tablegrid1.cells[0.0].AsString = ' Add A New Client'  then frmAddNewClient.show;
// says Strings do not have properties or methods

any ideas?

Thanx,
Keith

Maybe you are using dot(.) instead of comma(,)
try changing Cells[0.0] to Cells[0,0]

brian

Re: Addressing a TableGrid

Brian,

Good Eye !!

Keith

Re: Addressing a TableGrid

brian.zaballa wrote:
kweatherhead wrote:

Greetings,

I have a TableGrid on a form and I would like to grab the value of the first field in the first row... what is the proper
reference to grab that value?


Col1,  Col2,   Col3
xxx      yyy        zzz


I want to access  the "xxx", can someone please give me a example syntax.

Regards,
Keith

if Form1.TableGrid1.RowCount > 0 then begin
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsString);
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsFloat);
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsInteger);
    //ShowMessage(Form1.TableGrid1.Cell[0,0].AsDateTime); 
    ShowMessage(Form1.TableGrid1.Cells[0,0]); // string
end; 

Can you determine what row the user clicks on?  Where can you find out what the options are when dealing with Tablegrids, etc?

Regards,
Keith

Re: Addressing a TableGrid

try this one.

ShowMessage(Form1.TableGrid1.Cells[Form1.TableGrid1.SelectedRow,0]); // string

You can access the properties, functions etc by just typing the Grid, followed by dot(.)

Form1.TableGrid1.

then, Hit Ctrl+Spacebar. this will list down properties, functions, etc

brian

Re: Addressing a TableGrid

brian.zaballa wrote:

try this one.

ShowMessage(Form1.TableGrid1.Cells[Form1.TableGrid1.SelectedRow,0]); // string

You can access the properties, functions etc by just typing the Grid, followed by dot(.)

Form1.TableGrid1.

then, Hit Ctrl+Spacebar. this will list down properties, functions, etc

The showMessge line returns the Cell value, I was originally looking for the "SelectedRow" value.  1,2,3,5,10?

Thanx for the Ctrl+SpaceBar tip !!

Thanx,
Keith

9 (edited by derek 2021-02-12 13:55:12)

Re: Addressing a TableGrid

Hi Keith, Brian,
To get the position in the grid where you've clicked, you could try it like this (see attached).
If you just need to get the row id, you could also try form1.tablegrid1.getrowatpos(x,y) attached to an 'on_mouse_down' event.
Derek.

Post's attachments

Attachment icon kw.zip 340.54 kb, 267 downloads since 2021-02-12 

Re: Addressing a TableGrid

derek wrote:

Hi Keith, Brian,
To get the position in the grid where you've clicked, you could try it like this (see attached).
If you just need to get the row id, you could also try form1.tablegrid1.getrowatpos(x,y) attached to an 'on_mouse_down' event.
Derek.

Thanx to BOTH Brian & Derek !!!
As always the examples are very much appreciated ...
I had missed the reversed position reference initially  of   Col, Row  so that helps big time.

Regards,
Keith