Высота столбца в DBGrid в Delphi

Я использую компонент DBgrid в delphi 7.
Я хочу отображать столбцы таблицы в сетке.
Столбцы таблицы queryId,empid,empname and Query. Столбец Query имеет тип данных Text.

Столбец Query может содержать длинную строку. Но он отображается в одной строке.
Мне нужно исправить ширину столбцов, и в зависимости от данных высота для этой конкретной строки будет варьироваться.

Возможно ли в DBGrid изменить высоту строки, как это позволяет многострочный в одной записи, как в Excel?


person Nalu    schedule 22.12.2011    source источник
comment
Компонент SMDBGrid может обернуть столбец Recore?   -  person Nalu    schedule 22.12.2011


Ответы (1)


arrow_upward
0
arrow_downward

Посмотрите этот код . Это для TStringGrid, но вы знаете, что DBGrid и StringGrid являются производными от TCustomGrid. Итак, вы можете использовать код для DBGrid.

procedure DrawSGCell(Sender : TObject; C, R : integer; Rect : TRect;
          Style : TFontStyles; Wrap : boolean; Just : TAlignment;
          CanEdit : boolean);
  { draws formatted contents in string grid cell at col C, row R;
    Style is a set of fsBold, fsItalic, fsUnderline and fsStrikeOut;
    Wrap invokes word wrap for the cell's text; Just is taLeftJustify,
    taRightJustify or taCenter; if CanEdit false, cell will be given
    the background color of fixed cells; call this routine from
    grid's DrawCell event }
var
  S        : string;
  DrawRect : TRect;
begin
  with (Sender as tStringGrid), Canvas do begin
    { erase earlier contents from default drawing }
    if (R >= FixedRows) and (C >= FixedCols) and CanEdit then
      Brush.Color:= Color
    else
      Brush.Color:= FixedColor;
    FillRect(Rect);
    { get cell contents }
    S:= Cells[C, R];
    if length(S) > 0 then begin
      case Just of
        taLeftJustify  : S:= ' ' + S;
        taRightJustify : S:= S + ' ';
        end;
      { set font style }
      Font.Style:= Style;
      { copy of cell rectangle for text sizing }
      DrawRect:= Rect;
      if Wrap then begin
        { get size of text rectangle in DrawRect, with word wrap }
        DrawText(Handle, PChar(S), length(S), DrawRect,
          dt_calcrect or dt_wordbreak or dt_center);
        if (DrawRect.Bottom - DrawRect.Top) > RowHeights[R] then begin
          { cell word-wraps; increase row height }
          RowHeights[R]:= DrawRect.Bottom - DrawRect.Top;
          SetGridHeight(Sender as tStringGrid);
          end
        else begin
          { cell doesn't word-wrap }
          DrawRect.Right:= Rect.Right;
          FillRect(DrawRect);
          case Just of
            taLeftJustify  : DrawText(Handle, PChar(S), length(S), DrawRect,
                               dt_wordbreak or dt_left);
            taCenter       : DrawText(Handle, PChar(S), length(S), DrawRect,
                               dt_wordbreak or dt_center);
            taRightJustify : DrawText(Handle, PChar(S), length(S), DrawRect,
                               dt_wordbreak or dt_right);
            end;
          end
        end
      else
        { no word wrap }
        case Just of
          taLeftJustify  : DrawText(Handle, PChar(S), length(S), DrawRect,
                             dt_singleline or dt_vcenter or dt_left);
          taCenter       : DrawText(Handle, PChar(S), length(S), DrawRect,
                             dt_singleline or dt_vcenter or dt_center);
          taRightJustify : DrawText(Handle, PChar(S), length(S), DrawRect,
                             dt_singleline or dt_vcenter or dt_right);
          end;
      { restore no font styles }
      Font.Style:= [];
      end;
    end;
end;
person SimaWB    schedule 22.12.2011
comment
Спасибо за ответ. SetGridHeight - это процедура TstringGrid или что?? - person Nalu; 22.12.2011
comment
Я видел варианты этой процедуры по всему Интернету, но никто не объясняет, что такое SetGridHeight. - person user1355041; 22.05.2017