Forum > Databases

[Solved] DBGrid : add button in a cell to start the command "opendocument"

(1/2) > >>

folkeu08:
Hi boys,
I use a datase with a table who i record the link to a pdf file.
This link apear in a cell of a dbgrid.
I would like to add a button to the cell. By clicking on the button, the pdf viewer linked to the pdf extension should open the link of the file contained in its cell.
It is possible to add a button to each cell of the column of the DBGrid but it seems to me that this button is dedicated to edit the value of the cell. Is it this ? I will not be able to launch the "opendocument" command with the latter.
The solution would be to create a custom button for each cell in the column? Is the idea feasible?
I'm a beginner and not yet experienced enough to write this function.
Does anyone have this piece of code? I couldn't find anything from google
thanks in advance
Folkeu

tonyw:

--- Quote from: folkeu08 on August 23, 2022, 11:15:19 pm ---Hi boys,
I use a datase with a table who i record the link to a pdf file.
This link apear in a cell of a dbgrid.
I would like to add a button to the cell. By clicking on the button, the pdf viewer linked to the pdf extension should open the link of the file contained in its cell.
It is possible to add a button to each cell of the column of the DBGrid but it seems to me that this button is dedicated to edit the value of the cell. Is it this ? I will not be able to launch the "opendocument" command with the latter.
The solution would be to create a custom button for each cell in the column? Is the idea feasible?
I'm a beginner and not yet experienced enough to write this function.
Does anyone have this piece of code? I couldn't find anything from google
thanks in advance
Folkeu

--- End quote ---
Set the button style to elipses.
Then add a OnEditButtonClick event handler tot he TDBGrid.
In the Event handler use the TDBGrid.SelectedField property to get the field for the current cell. If this is the field holding the path the the document then retrieve the document path and open the document

dje:
I've attached a simple example of the TDBGrid buttons. Hope that helps.

folkeu08:
Hi dje,

Thanks for your example.
On my personal PC, the example works fine.
At my work, I also did the test and it does not detect the file. "No File" in the option cell. The pdf extension is well associated with acrobat reader.
I will look for the file that is in the Lazarus installation at: C:\Lazarus_2.2.2\fpc\3.2.2\source\packages\fcl-stl\doc\main.pdf
I put a screenshot.
Thanks
Folkeu

dje:
Could be the string field size.

Navigation

[0] Message Index

[#] Next page

Go to full version