views:

213

answers:

2

I've got a TdxDBGrid that's displaying some information retrieved from a database query. One of the columns is a Memo column, (TdxDbGridMemoColumn,) which is necessary because the data in the field it's bound to comes out of the database as type TEXT, not CHAR or VARCHAR.

Problem is, the memo column likes to display whole words, and if it can't display a whole word, it doesn't display any part of it. The normal grid columns show everything they can up to the right border and cut off the display there, but the memo column doesn't, and that's bound to confuse end-users. Is there any way I can get the memo column to display partial words?

+1  A: 

You could owner-draw the column. Then you can make the text look however you want. Call DrawText and use the dt_End_Ellipsis flag to draw an ellipsis on the end of long text, or else just let the long text be clipped to the drawing area.

Rob Kennedy
+1  A: 

in the onGetText event of the column, you can modify the displayed text to accommodate the available size:

// the TTextFormats flags are defined in Graphics, add it to your uses clause
procedure TMyForm.gridMyColGetText(Sender: TObject; ANode: TdxTreeListNode;
  var AText: string);
var
  R: TRect;
begin
  // Calculate actual displayable text (with ellipsis) depending on cell size
  R := (Sender as TdxDBGridColumn).TreeList.CellRect(ANode, (Sender as TdxDBGridColumn).ColIndex);  // get the cell rectangle
  Windows.InflateRect(R, -2, 0); // shrink a bit for grid lines
  grid.Canvas.TextRect(R, AText, [tfModifyString, tfEndEllipsis]); // shorten the text ...
end;
François