Author: Tomas Rutkauskas
How to display memo fields in a TDBGrid
Answer:
1 2 procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
3 Field: TField; State: TGridDrawState);
4 var5 P: array[0..50] of char; {array size is number of characters needed}6 BS: tBlobStream; {from the memo field}7 S: string;
8 begin9 if Field is TMemoField then10 begin11 with (Sender as TDBGrid).Canvas do12 begin13 BS := tBlobStream.Create(TBlobField(Field), bmRead);
14 FillChar(P, SizeOf(P), #0); {terminate the null string}15 BS.read(P, 50); {read 50 chars from memo into blobStream}16 BS.Free;
17 S := StrPas(P);
18 while Pos(#13, S) > 0 do19 S[Pos(#13, S)] := ' ';
20 while Pos(#10, S) > 0 do21 S[Pos(#10, S)] := ' ';
22 FillRect(Rect); {clear the cell}23 TextOut(Rect.Left, Rect.Top, S); {fill cell with memo data}24 end;
25 end;
26 end;
For mouse right click behavior you need to intercept the right click mouse message.