Topic: How to reference a fields from a grid

I have a tablegrid which has three columns, A,B,C.  I want to have a button that will run a sql query based on a record selected.

How do I reference the values from column A, B,C into my sql query?

I know if I have an edit field - I can reference as {editfieldname}.  I am not sure how to reference the values from the selected row into distinct values in the resultant SQL.

Your assistance is appreciated.

Thank you,
  Rob

Re: How to reference a fields from a grid

Looking at the help file, if the field/column of the wanted value (A, B, or C) is already selected on the current record, then you should use the sqlValue property:

e.g. SQLExecute ('INSERT INTO tablename (id_groups) VALUES ('+Form1.TableGrid1.sqlValue+')');

If only the row is selected, but the field is not, or you want other fields, then you would use a combination of the function Cells and the function SelectedRow:

e.g. ShowMessage('value of column A: ' + Cells(1,Form1.TableGrid1.SelectedRow));

The above assumes that column A had index 1.

Dennis

Re: How to reference a fields from a grid

rjkantor
You use the button with the action "SQL Query"?
Like an edit field, you can reference TableGrid1 as {TableGrid1} in SQL in this way you get id selected record.

Dmitry.

Re: How to reference a fields from a grid

DriveSoft wrote:

rjkantor
You use the button with the action "SQL Query"?
Like an edit field, you can reference TableGrid1 as {TableGrid1} in SQL in this way you get id selected record.

If i wanted to use the value in a where clause - how do I use the specific  column, by name reference or Index?

where a.id = {tablegrid1.C}  name reference
where a.id = {tablegrid1.index(3)}  index reference

Re: How to reference a fields from a grid

This seems to show the proper value when I use showmessage

b.[Order Number]='{frmListOrder.TableGrid1.Cells[3,frmListOrder.TableGrid1.SelectedRow]}'

Although when I add to my  sql where clause I am not getting any values in the tablegrid.

Re: How to reference a fields from a grid

rjkantor
It works by another method.
Can you send me your project to support@drive-software.com
With description, what exaclty you need to do.

Dmitry.

Re: How to reference a fields from a grid

I emailed my project with description of what I am trying to achieve.

Re: How to reference a fields from a grid

Thank you for the examples via my project.  I did not realize you can use the grid as a component to be used from the search button.

Rob

Re: How to reference a fields from a grid

Yes, you can use the TableGrid for results and using it for a search (like ComboBox).

Dmitry.