以下代码是整个dbgrid改变,我要改变选中的一列,怎么做?
procedure TForm1.Button1Click(Sender: TObject);
begin
if form1.FontDialog1.Execute then form1.DBGrid1.Font:=form1.FontDialog1.Font;
end;

解决方案 »

  1.   

    DBGrid的事件OnDrawDataCell中
    procedure TForm1.DBGDrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
         if ADOQuery1.FieldByName('Cancel').AsBoolean = True then ///////选中的Cancel列
         begin
            //字体
            DBGrid1.Canvas.Font.Color := clRed;//字体色
            //背景
            DBGrid1.Canvas.Brush.Color:= $005959FF;
            DBGrid1.Canvas.FillRect(Rect);
        end;
        DBGrid1.DefaultDrawDataCell(Rect, Field, State);
    end;  
      

  2.   

    我是要让最终用户随意改变啊?
    我想可以用checklistbox或listview把dbgrid的所有字段或caption加上去,可是怎样判断我选择的是哪一列呢?还有当click button时checklistbox或listview已经失去焦点。
      

  3.   

    if FontDialog1.Execute then 
    DBGridEh1.Columns[checklistbox.ItemIndex].Font:=FontDialog1.Font;