0
votes

I have a DBGrid that is linked to DataSource (that is linked to TADOTable). All this runs through a TADOConnection and connects to a MS Access

The grid contains various values and I would like to edit it when I click on a specific field. I'm not experiencing any difficulty updating normal text fields, however I can't get a way to edit fields that contain an OLE Object.

What I want to do is, when I click a field, I want a open dialog box to open and let me select a file. After that, the file that I selected, must be updated to the field of the row I selected.

How would I go about doing this?

1
DevExpress QuantumGrid has this and many more features. devexpress.com/Products/VCL/ExQuantumGridAdam
Thank you, but is there any way to implement this without using non-standard components?coder123
You may want to try the columns property of the grid. Here you can define a column as having an ellipsis button, you can then handle the event... this may provide the type of functionality you are looking for..GDF
You can drop a button and opendialog to the form. Make the button invisible. Adjust the size & position of the button in the grid onDrawColumnCell. Make the button invisible on grid col exit. In onclick event of the button, execute the opendialog, get the filename, put the dbgrid in edit state, and update the field with the selected file. Some tutorials exist on (delphi.about.com/od/usedbvcl/l/aa081903a.htm) how to add varius component to dbgrid. With modification like above, you can achive what you want.Hendra

1 Answers

0
votes

Figured it out myself. Posting it here so that others can benefit. I just went to my DBGrid and in object inspector, under events, I selected OnCellClick:

procedure TfrmOne.dbgOneCellClick(Column: TColumn);
begin
var
  line : integer;
begin
  line := DataSource1.DataSet.FieldValues['ID'];

As you can see, line gets the field value of the selected row, in this case the ID. Each row has its unique ID (Primary Key), linking/coming from the database. With this primary key, I did a simple IF statement:

tblOne.Close;
tblOne.Open;
tblOne.First
while not tblOne.Eof do
if tblOne['ID'] = line then
begin
 if OpenDialog1.Execute then
  {*Insert Code here*}
 Exit;
end else
 tblOne.Next;
end;

Basically what happens in the second piece of code is, the ID is matched to the current table row. If it does not match, the database moves on one row, until it is eventually a match. From here one can specifically work with that row (as originally seen/selected in the DBGrid) and update fields (OLE Object).

This is not a replacement for the Append or Edit command, it merely allows a user to execute a opendialog and then save those files to the selected field in the DBGrid. Take note, for adding photos to the database (jpeg), you will need blobstreams etc. A full guide can be found here: http://delphi.about.com/od/database/l/aa030601a.htm