DB Grid Question...

I'm using a DB Grid to display the contents of a database. The Memo field though doesn't show up, it just says: (MEMO).  How can I have it display the contents of the Memo field when the box is double-clicked?
dokkenAsked:
Who is Participating?
 
Phoenix_sConnect With a Mentor Commented:
My answer.... ;)

Cheers!
0
 
intheCommented:
hi,
try this DrawMemoCell proc  adapted straight from Borlands Delphi FAQ :
 
 
procedure TResultsForm.DBGrid1DrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
begin
  if Field is TMemoField then
    DrawMemoCell( Sender, Rect, ResultsTable, 'TITLE');
end;
 
procedure DrawMemoCell( Sender: TObject; const Rect: TRect;
                        xTable: TTable; cField: string );
var
  cChars  : array [0..501] of char;  {array size is number of characters needed}
  xBlob  : TBlobStream;              {from the memo field}
  cStr    : string;
begin
  with (Sender as TDBGrid).Canvas do begin
    {Table1Notes is the TMemoField}
    xBlob := TBlobStream.Create( TBlobField( xTable.FieldByName(cField)), bmRead );
    FillChar( cChars, SizeOf( cChars ), #0 );  {terminate the null string}     xBlob.Read( cChars, 500 );    {read chars from memo into blobStream}     xBlob.Free;
    cStr := StrPas( cChars );
    while Pos( #13, cStr ) > 0 do              {remove carriage returns and}       cStr[ Pos( #13, cStr )] := ' ';          {line feeds}
    While Pos( #10, cStr ) > 0 do
      cStr[ Pos( #10, cStr )] := ' ';
    FillRect( Rect );                          {clear the cell}
    TextOut( Rect.Left + 3, Rect.Top + 2, cStr )      {fill cell with memo data}
  end;
end; {DrawMemoCell}
 

Regards Barry
0
 
Phoenix_sCommented:
you could put up a memo component under the grid which'd show the memo data as the records scrolled by on the grid, or if you even want to have a small modal window show up by clicking on the field in the grid

all's you'd have to do for the latter is stick a click event on the grid which'd open the memo display dialog

ex.  make a small form, stick a dbmemo on it.

in the gridclick event... create the form, set the datasource property of the memo control to the calling form's datasource, show it modally, then dispose of it when you're done


hope this helps... ;)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
dokkenAuthor Commented:
Barry,

I'm using that DBISAM database component and the TTable turned out to not be compatible with it.

Phoenix,

Your method works great. Post something as an answer so I can give you the points.

0
 
rajeshveeCommented:
U can place a DB MEMO in the form .
Set it's  datafield and datasource.
On the Gird's MouseClick get the coordinates of the memo cell using function CellRect.
Set the DBMEMO's coordinates to the grids cells  using function Setbounds .

0
 
dokkenAuthor Commented:
Phoenix,

Thanks again for the answer.
0
All Courses

From novice to tech pro — start learning today.