我也是查以前的贴知道的
procedure TZFMF.GridZHJDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  vText:PChar;
begin
  with TStringGrid(Sender) do
    begin
      if ARow=0 then Canvas.font.color:=clMaroon
      else Canvas.font.color:=clWindow;//clBlack;
      vText := PChar(Cells[ACol, ARow]);
      Canvas.FillRect(Rect);
      DrawText(Canvas.Handle, vText, StrLen(vText), Rect,
      DT_CENTER or DT_VCENTER or DT_SINGLELINE); //<<--
    { TODO : 修改对齐方式 }
    if gdFocused in State then begin
      Rect.Left := Rect.Left + 1;
      Rect.Top := Rect.Top + 1;
      Rect.Right := Rect.Right - 1;
      Rect.Bottom := Rect.Bottom - 1;
      Canvas.DrawFocusRect(Rect);
    end;
  end;   end;

解决方案 »

  1.   

    上面的程序不明白啊,
    这个控件我也一直在用,可是,这些问题却一直得不到很好的解决。在许多情况下都是用stringgrid来代替dbgrid。谁有好的办法说说看。
      

  2.   

    上面那段代码只能解决你第一问题, 你在stringgrid的DrawCell事件里写入这段代码就可以了
      

  3.   

    在StringGrid的自绘事件中写上如下代码:
    procedure TForm2.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      Txt:String;
    begin
      Txt:=StringGrid1.Cells[ACol,ARow];
      StringGrid1.Canvas.Rectangle(Rect);
      DrawText(StringGrid1.Canvas.Handle,
               Pchar(Txt),
               Length(Txt),
               Rect,
               DT_CENTER or DT_VCENTER );
      //在StringGrid单元格画内画字符串
    end;
      

  4.   

    prcedure TForm1.IsEdit;
    begin
      with stringgrid1 do
      begin
      if col=4 then
        options:=[goFixedVertLine,goFixedHorzLine,goColMoving,goEditing]
       else
         options:=[goFixedVertLine,goFixedHorzLine,goColMoving]
      end;
    end;
      

  5.   

    第2问题解决方案有2
    1)在StringGrid的KeyPress事件中加入
      key := #0
    2)在StringGrid的OnSelectCell事件中
      if(ACol = 某列值) then CanSelect := false;