你这个没必要用DELPHI,用SQL语句就很轻易实现了 给你写个SQL的例子select case when field1=1 then * else field1 end from yourtable
给你参考 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var ShowStr: string; begin if Column.FieldName = 'sex' then begin if Column.Field.AsString = '0' then ShowStr:='女' else if Column.Field.AsString = '1' then ShowStr:='男' else ShowStr:=''; DBGrid1.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,ShowStr); end; end;
给你写个SQL的例子select case when field1=1 then * else field1 end from yourtable
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
ShowStr: string;
begin
if Column.FieldName = 'sex' then
begin
if Column.Field.AsString = '0' then
ShowStr:='女'
else if Column.Field.AsString = '1' then
ShowStr:='男'
else
ShowStr:='';
DBGrid1.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,ShowStr);
end;
end;