Can I reformat cell text based current data row?

Using TDBAdvGrid I'm trying to manipulate information to perform on-the-fly calculations before displaying text in certain cells. An example might be formatting log-in/log-out times for application users followed by a calculated time duration. The database records contain the user names along with the times in and out, but no value for the overall duration. How can this be done using the existing grid events, datasources, and cell captioning features?


A possible solution could be to implement the OnGetDisplText event. In this event, you can full define the content of the cell based on the original value in the DB field.

I've tried to retrieve data for the current record during "OnGetDisplText" and I seem only to get the value of the first record in the result set... It's strange all of the data that is automatically populated looks fine, but it's as though that was all done before the grid was painted. Here's a code snippet:

procedure TForm1.grdResultsGetDisplText(Sender: TObject; ACol, ARow: Integer; var Value: string);
  // Get the value from the database, then add something to it...
  Value:= srcResults.DataSet.FieldByName('UserName').AsString ) + '...';

The following is a comma delimited representation of the source data...
ColUserName, ColUserStartTime
'Bob', '12:30pm'
'Fred', '4:15pm'
'James', '6:45pm'

Here's a comma delimited representation of the information displayed in the grid...
'Bob', '12:30pm', 'Bob...'

'Fred', '4:15pm', 'Bob...'

'James', '6:45pm', 'Bob...'

What else should I be looking at?

Please use the Value parameter of the event instead of DataSet.FieldByName()

I'm not sure I understand... the value parameter will contain nothing for the 3rd column because the source dataset on which the grid was based contained no such column. In our software the column is added following the query.

To clarify, I'm trying to get values from the database while the grid is being populated. Sort of like a calculated field. In this scenario my database contains data of various types, the "Value" property seems only good for strings... What if my query included 3 columns, Name(String), StartDate(DateTime), EndDate(DateTime), is there some way that I could capture the traversal event and format the text myself based on the current position in the dataset?

PS. This is what we used to do with "TopGrid".

I'm still stuck, Any Ideas?

You cannot use dataset.FieldByName(). Please assign the field in a column (possibly a hidden column) and access the values in OnGetDisplText via grid.Cells[]

Thanks, That may be a viable solution.
Question... do you have any sample code for calculated columns?

This is something that is defined on dataset level,

the article
might help you for that.