DBGrid 中字段显示问题,如果对应字段在数据库中是bit性,在用户界面显示时需要显示是“是”或“否”,请各位大侠指点一二,先谢那!!

解决方案 »

  1.   

    在drawcolumncell事件裡面處理:procedure TDelyList_frm.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    const
    CtrlState :array[Boolean] of Integer=(DFCS_BUTTONCHECK,DFCS_BUTTONCHECK or DFCS_CHECKED);
    begin
      if Column.Field.DataType =ftBoolean then
       begin
           DBGrid1.Canvas.FillRect(Rect);
           DrawFrameControl(DBGrid1.Canvas.Handle,Rect,DFC_BUTTON,CtrlState[Column.Field.AsBoolean]);
       end;
    end;
      

  2.   

    在DBGrid的DrawColumnCell事件中procedure TfrmBetterCust.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    var
       str:string;
    begin
      if Column.FieldName='是否' then   //字段为"是否"
      begin
        str:=Column.Field.AsString ;
        if str='0' then
          begin
           DBGrid1.Canvas.Font.Color:=clRed;
           DBGrid1.Canvas.TextOut(Rect.Left+1,Rect.Top+2,'是');
          end
        else if str='1' then
          begin
           DBGrid1.Canvas.Font.Color:=clBlue;
           DBGrid1.Canvas.TextOut(Rect.Left+1,Rect.Top+2,'否');
          end;
      end
      else
        DBGrid1.DefaultDrawDataCell(Rect,Column.Field,state);
    end;OK!搞定了!
      

  3.   

    要这么麻烦吗?
    在数据集(如:TADOQUERY)中设置永久字段不就搞定了吗,
      

  4.   

    呵呵,楼上各位都太夸张了,我来个更夸长的select sex , 
          case sex 
             when true then '男' 
             when false then '女' 
             when null then '人妖' 
           end as 性别 
    from employee
      

  5.   

    如果通过Query连接
    可以设置该布尔性字段的DisPlayValues设为:是;否
    显示时就会显示是或否了
      

  6.   

    procedure Tform.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
     
    TBooleanField(adoquery1.fieldbyname('flag')).DisplayValues:='是;否';
    //flag为字段名
    end;
      

  7.   

    1、双击dataset,右键菜单add all fields,写那个field的 OnGetText 事件
    if(sender.AsInteger=0)then
      Text:='男'
    else
      Text:='女';