当前位置:主页>销售管理软件> 列表

DBGrid问题!! 找用友财务软件试用版

销售管理软件版1楼: 我现在用DBGrid和ADOQuery显示数据,我在数据库当中的字段中是存的number(1)类型的值0和1,显示的时候我想让DBGrid显示为真或假,即
当字段值为1时显示为“真”
当字段值为0时显示为“假”
请指点!!

2楼: 没有人回答吗,我以前用过这个功能,但是现在忘了,当时的资料也找不着了,还请高手指点一下。 如进销存软件

3楼: 在adoquery里选中这个字段,然后在ongettext事件里编写代码即可。

4楼: 能具体说说怎么写吗,还可能用DBGrid重画的事件来实现吗?

5楼: 建立一个计算字段,在onCaculate中写
if 表字段=1 then 计算字段=‘真’

6楼: 1,在sql语句中转换,select case zd when 0 then ''假'' ,when 1 then ''真'' end as zdzh from table
2,用计算字段,有人回答了

销售管理软件版7楼: 这个问题没有人知道吗?我不想在写SQL语句的时候变化,只想在数据导入到DBGrid的时候替换一下,怎么写,我忘了,以前用过这种功能。

8楼: 在字段的 OnGetText 和 OnSetText 中写。

9楼: 1,在sql语句中转换,select case zd when 0 then ''假'' ,when 1 then ''真'' end as zdzh from table
2,用计算字段,有人回答了

10楼: 在 OnGetText 中写:
if Sender.Value=''1'' then Text:=''true''
else Text:=''false'';

在 OnSetText 中写:
if LowerCase(Text)=''true'' then Sender.Value:=''1''
else Sender.Value:=''0'';

11楼: 相应字段的TField.DisplayVales:=''真;假'';
用SQL转换或计算字段将不能直接编辑

12楼: 能具体给出怎么写吗?在什么地方添加事件? 如用友财务软件试用版

13楼: procedure TDataModule1.ADOQuery1YourFieldGetText(Sender: TField;
var Text: string; DisplayText: Boolean);
begin
if Sender.Value=1 then Text:=''true''
else Text:=''false'';
end;

procedure TDataModule1.ADOQuery1YourFieldSetText(Sender: TField;
const Text: string);
begin
if LowerCase(Text)=''true'' then Sender.Value:=1
else Sender.Value:=0;
end;

销售管理软件版14楼: kaida,你好,我还是不知道怎么加事件,是自己手动添加的吗,因为我的adoQuery是共用的,不是静态设置好Fields的,所以我也没办法自动添加事件,应该怎么办??

15楼: 下面是带对勾的写法


procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if TDBGrid(Sender).Fields[DataCol].DataType=ftBoolean then
begin
TDBGrid(Sender).Canvas.FillRect(rect);
if TDBGrid(Sender).Fields[DataCol].IsNull then
ImageList.Draw(TDBGrid(Sender).Canvas,Rect.Left+3,Rect.Top +1,3 )
else
if TDBGrid(Sender).Fields[DataCol].AsBoolean then
begin
if (gdFocused in state) or (gdSelected in state) then
ImageList.Draw(TDBGrid(Sender).Canvas,Rect.Left+3,Rect.Top +1,2 )
else
ImageList.Draw(TDBGrid(Sender).Canvas,Rect.Left+3,Rect.Top +1,1 )
end
else
ImageList.Draw(TDBGrid(Sender).Canvas,Rect.Left+3,Rect.Top +1,0 );
end
else
TDBGrid(Sender).DefaultDrawColumnCell(Rect,DataCol, Column,State);

end;

procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
if dgRowSelect in TDBGrid(column.Grid).Options then exit;
if column.Field.ReadOnly then exit;
if column.ReadOnly then exit;
if column.Field.DataType=ftBoolean then
begin
if column.Field.DataSet.State<>dsEdit then column.Field.DataSet.Edit;
if (column.Field.IsNull) or (not column.Field.AsBoolean) then
column.Field.AsBoolean :=true
else
column.Field.AsBoolean :=false;
end;
end;

其中ImageList里有四个图标是对勾图标的状态

16楼: 你先按我上面说的,手工编写:
type
TDataModule1 = class(TDataModule)
......
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
[red]procedure ADOQuery1YourFieldGetText(Sender: TField;
var Text: string; DisplayText: Boolean);
procedure ADOQuery1YourFieldSetText(Sender: TField; const Text: string);[/red]
public
{ Public declarations }
end;
......
[red]procedure TDataModule1.ADOQuery1YourFieldGetText(Sender: TField;
var Text: string; DisplayText: Boolean);
begin
if Sender.Value=1 then Text:=''true''
else Text:=''false'';
end;

procedure TDataModule1.ADOQuery1YourFieldSetText(Sender: TField;
const Text: string);
begin
if LowerCase(Text)=''true'' then Sender.Value:=1
else Sender.Value:=0;
end;[/red]
然后在 DataModule 的 OnCreate 中:
procedure TDataModule1.DataModuleCreate(Sender: TObject);
begin
[red] ADOQuery1.FieldByName(''YourField'').OnGetText:=
ADOQuery1YourFieldGetText;
ADOQuery1.FieldByName(''YourField'').OnSetText:=
ADOQuery1YourFieldSetText;[/red]
end;
红色部分是手工编写的。

17楼: procedure TForm1.ADOTable1spendGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
if DisplayText then
begin
text:=ADOTable1spend.Value;
insert('' ¥'',text,ADoTable1spend.Size);
end;
end;]

18楼: 多人接受答案了。