2011-12-22 2 views
2

델파이 7에서 DBgrid 구성 요소를 사용하고 있습니다.
그리드에 표 열을 표시하고 싶습니다.
테이블 열은 queryId,empid,empname and Query입니다. Query 열의 데이터 유형이 텍스트로 설정되어 있습니다.Delphi에서 DBGrid의 열 높이

쿼리 열에 긴 문자열이 포함될 수 있습니다. 그러나 그것은 한 줄에 표시됩니다.
열의 너비를 수정해야하며 데이터에 따라 높이가 해당 행에 따라 달라집니다.

DBGrid에서 행의 높이를 변경하는 것이 Excel과 비슷한 단일 레코드에서 여러 행을 사용할 수 있습니까?

+0

SMDBGrid 구성 요소가 Recore 열을 래핑 할 수 있습니까? – Nalu

답변

0

this 코드입니다. 그것은 TStringGrid를위한 것이지만, DBGrid와 StringGrid는 TCustomGrid에서 파생 된 것입니다. Sou 당신은 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; 
+0

답장을 보내 주셔서 감사합니다 .. SetGridHeight는 TstringGrid 프로 시저 또는 무엇입니까 ?? – Nalu

+0

인터넷을 통해이 절차의 변형을 보았지만 아무도 SetGridHeight가 무엇인지 설명하지 않습니다. – user1355041