1 (edited by CDB 2020-05-01 10:00:56)

Topic: Out of interest question on tablegrid oncell click

I have a table grid which is filled using a SQL statement - purely because the data comes from multiple tables.



The table is read only. The idea is that via scrolling or a search, an item is found, and when clicked on, the row appears in a number of text edits ready for editing.



My first attempt in the OnCellClick procedure was:


frmEditPart.edtEditDescription.Text := sqlexecute('SELECT description FROM productsupplier WHERE id=' +intToStr(frmEditPart.grdEditPart.dbItemID));


Now, that produces a -1 on the first click on the cell, but works correctly after that.


So I experimented with :


frmEditPart.edtEditDescription.Text := sqlexecute('SELECT description FROM productsupplier WHERE id=' +(frmEditPart.grdEditPart.sqlvalue));


That produces a NULL on the first click and then works as expected after that.

I worked around the problem by


frmEditPart.edtEditDescription.Text := frmEditPart.grdEditPart.Cells[1,Arow];


However, I'm puzzled as to why the previous two attempts produce this NULL.

On a clear disk you can seek forever

Re: Out of interest question on tablegrid oncell click

CDB,
Not sure what is happening on your end, but I checked it out and it works fine on this end. I tried on version 6.2, 6.3 and 6.4 and retrieving the record on the OnCellClick event works, Maybe attach your project and we can take a look.

3 (edited by CDB 2020-05-03 23:13:03)

Re: Out of interest question on tablegrid oncell click

Hi ehwagner,


Attached is my project so far that has the problem of returning -1 when the tablegrid is clicked for the first time.


From frmMain click on the Part Maintenace tab and then on  the EDIT button. Six items will appear in the table grid.


Click on any of the five items and the text boxes on the left will be filled out waiting to be edited if needs be.


I have a further problem - I cannot get the items in the part_categories table to match the foreign key in the products table.  No matter what I try the part category is not in sync. The database does have the correct entries in the products table.

You will see that in the OnCellClick event for the table I've put in some debugging code.

The part categories I should be seeing in order of the products listed in the table grid is:

A2D/Scalar card    ID 7
A2D/Scalar card    ID 7
A2D/Scalar card     ID 7
Power Supply        ID 6
Component            ID 3
Component            ID 3


I'm using v6.3.


PS: I've just realised this build does not have the foreign key in products - I'd taken it out while sorting  out a DB corruption.

Post's attachments

Attachment icon workshopPartsDB_V04.zip 1.62 mb, 490 downloads since 2020-05-03 

On a clear disk you can seek forever

Re: Out of interest question on tablegrid oncell click

CDB,
When you build a tablegrid manually or through SqlQuery and you need to get to the dbitemId for editing, etc you need to include id in your SELECT. See below. If you do not want to see the id in the tablegrid, then you insert "delete_col" in its place in the FieldNames. 

procedure frmEditPart_OnShow (Sender: TObject; Action: string);
begin

     frmEditPart.grdEditPart.dbSQL :='SELECT p.id,p.LineNumber, i.description,p.partModel FROM products p, productsupplier i INNER JOIN products ON ' +
     'p.id = i.id GROUP BY p.id ORDER BY p.lineNumber ASC;' ;

    frmEditPart.grdEditPart.dbListFieldsNames:= 'delete_col,BSuite#,Description,Model,Part Code,Supplier';
    frmEditPart.grdEditPart.dbSQLExecute;

end;

Categories work now too.

Post's attachments

Attachment icon workshopParts_Revised.zip 1.61 mb, 492 downloads since 2020-05-04 

Re: Out of interest question on tablegrid oncell click

Thanks ehwagner,

That has solved the -1 problem, it hasn't solved why clicking on the grid fills out all the correct items apart from Category.

I shall try and work out why this one field is not behaving.

On a clear disk you can seek forever

6 (edited by ehwagner 2020-05-04 04:21:27)

Re: Out of interest question on tablegrid oncell click

CDB,
Look in my project. The categories work. You need to populate the combobox dbitemId from the Products id_part_categories. Look at the statement underneath the one where you populate the description.

Re: Out of interest question on tablegrid oncell click

Thank you for putting me on the right track ehwagner,

Your help is gratefully received.

On a clear disk you can seek forever