具有行高度变量的DBGRID

时间:2015-08-27 18:10:14

标签: delphi delphi-xe

我想在DBGRID中显示如下:

想象一下“网格”如下:

ID - 说明

1 - 网格的第1行
2 - 网格的第2行
3 - 网格的第3行

现在,假设DESCRIPTION列的大小已更改,并且不再出现单词“GRID”;

我想留下DBGRID

ID - 说明

1 - 中的第1行 网格
2 - 中的第2行 电网
3 - 中的第3行 电网
是否有任何可能性??

1 个答案:

答案 0 :(得分:2)

不是你问的问题,但可能有所帮助......我曾经使用这段代码在标准DBGrid中显示完整的Memo字段:

config.codekit

对于Blob / Memo字段,您可能还会发现做一些自定义GetText直接在网格中显示内容很有用:

  TMyForm = class(TForm)
    ...
  private
    FormMemoRect: TRect;
    MemoGrid: TDBGrid;
    BMemo: TBitBtn;
    ...

Procedure TMyForm.FormMemoDeactivate(Sender: TObject);
Begin
    (Sender As TForm).Close;
    Sender.Free;
End;

Procedure TMyForm.BMemoClick(Sender: TObject);
Var FormMemo: TForm;
Begin
    MemoGrid.SetFocus;

    FormMemo := TForm.Create(Self);
    With TMemo.Create(FormMemo) Do Begin
        Parent := FormMemo;
        Align := alClient;
        ReadOnly := True;
        WordWrap := True;
        ScrollBars := ssVertical;
        Lines.Text := MemoGrid.DataSource.DataSet.Fields[TComponent(Sender).Tag].AsString;
    End;

    With FormMemo Do Begin
        OnDeactivate := FormMemoDeactivate;
        Left := FormMemoRect.Left;
        Top := FormMemoRect.Top;
        Width := Max(FormMemoRect.Right - FormMemoRect.Left, 300);
        Height := FormMemoRect.Bottom - FormMemoRect.Top;
        BorderStyle := bsNone;

        Show;
    End;
End;

Procedure TMyForm.GrdMemoDrawColumnCell(Sender: TObject; Const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
Begin
    If (gdFocused In State) Then Begin
        If Column.Field.DataType In [ftBlob, ftMemo] Then Begin
            {Desenha botão para visualização do Memo}
            FormMemoRect.Left := TWinControl(Sender).ClientToScreen(Rect.TopLeft).X;
            FormMemoRect.Right := TWinControl(Sender).ClientToScreen(Rect.BottomRight).X;
            FormMemoRect.Top := TWinControl(Sender).ClientToScreen(Rect.BottomRight).Y;
            FormMemoRect.Bottom := FormMemoRect.Top + 100;

            If Not Assigned(BMemo) Then
                BMemo := TBitBtn.Create(Self);
            BMemo.Parent := TWinControl(Sender).Parent;
            BMemo.Width := 16;
            BMemo.Height := 16;
            BMemo.Caption := '...';
            BMemo.OnClick := BMemoClick;
            BMemo.Tag := Column.Field.Index;
            BMemo.Left := TWinControl(Sender).Left + Rect.Right - BMemo.Width + 1;
            BMemo.Top := TWinControl(Sender).Top + Rect.Top + 2;

            MemoGrid := TDBGrid(Sender);
        End
        Else
            FreeAndNil(BMemo);
    End;
End;

这就是结果的样子。 Memo on Grid

PS:很抱歉非标准代码风格。