在DBGrdDrawColumnCell事件中写代码 if ansicomparetext(Column.FieldName,fieldname)=0 then column.Grid.Canvas.TextRect(rect,rect.left,rect.Top,'是、否');
1、在DBGrdDrawColumnCell写; 2、最好在对应用就字段的SetText和GetText事件中写 ————————————————————————————————— MaximStr := '宠辱不惊,看庭前花开花落,去留无意; 毁誉由人,望天上云卷云舒,聚散任风。'; if Not Assigned(I) then I := TI.Create(Nil); I.Maxim := MaximStr; I.Explain := '假如上述代码中出现“OA”、“3D”等字样,改为“=”等'; I.Desire := '加不加分随你'; —————————————————————————————————
DBGRID对应的dataset即相应的table或query的字段级 //显示时 有ongettext事件: if sender.asboolean=true then//我记得应该为sender.asboolean=1吧 text:='是' else text:='否'; //设置时 有onsettext事件: if text='是' then begin Query1.edit; Query1.fieldbyname('字段').asboolean=true; end else begin if text='否' then begin Query1.edit; Query1.fieldbyname('字段').asboolean=false; end else begin Query1.edit; Query1.fieldbyname('字段').clear; end;
end;
DBGRID对应的dataset即相应的table或query的字段级 //显示时 有ongettext事件: if sender.asboolean=true then//我记得应该为sender.asboolean=1吧 text:='是' else text:='否'; //设置时 有onsettext事件: if text='是' then begin Query1.edit; Query1.fieldbyname('字段').asboolean=true; end else begin if text='否' then begin Query1.edit; Query1.fieldbyname('字段').asboolean=false; end else begin Query1.edit; Query1.fieldbyname('字段').clear; end;
嘻嘻,大虾扪都不肯出手,只好我来了. 步骤如下:1:右键单击dbgrid=>columns editor->add all fields 然后选中您需要设置的那一个column,设置它的picklist属性.(把'是''否'添加进去)
此时您运行程序时当然会出错了,嘻嘻,因为类型不对嘛. 步骤二.右键单击table1,fields editor->addallfields 选中您需要设置的那一个字段.在它的GetText事件里面写上: inherited; if Sender.AsBoolean = true then Text := '是' else if Sender.asboolean =flalse then Text := '否' else Text := ''; 在它的on settext事件里面写上 inherited; if Text = '是' then Sender.Asboolean :=true else if Text = '否' then Sender.Asboolean :=false ================over===========
if ansicomparetext(Column.FieldName,fieldname)=0 then
column.Grid.Canvas.TextRect(rect,rect.left,rect.Top,'是、否');
2、最好在对应用就字段的SetText和GetText事件中写
—————————————————————————————————
MaximStr := '宠辱不惊,看庭前花开花落,去留无意;
毁誉由人,望天上云卷云舒,聚散任风。';
if Not Assigned(I) then
I := TI.Create(Nil);
I.Maxim := MaximStr;
I.Explain := '假如上述代码中出现“OA”、“3D”等字样,改为“=”等';
I.Desire := '加不加分随你';
—————————————————————————————————
//显示时
有ongettext事件:
if sender.asboolean=true then//我记得应该为sender.asboolean=1吧
text:='是'
else
text:='否';
//设置时
有onsettext事件:
if text='是' then
begin
Query1.edit;
Query1.fieldbyname('字段').asboolean=true;
end
else
begin
if text='否' then
begin
Query1.edit;
Query1.fieldbyname('字段').asboolean=false;
end
else
begin
Query1.edit;
Query1.fieldbyname('字段').clear;
end;
end;
//显示时
有ongettext事件:
if sender.asboolean=true then//我记得应该为sender.asboolean=1吧
text:='是'
else
text:='否';
//设置时
有onsettext事件:
if text='是' then
begin
Query1.edit;
Query1.fieldbyname('字段').asboolean=true;
end
else
begin
if text='否' then
begin
Query1.edit;
Query1.fieldbyname('字段').asboolean=false;
end
else
begin
Query1.edit;
Query1.fieldbyname('字段').clear;
end;
end;
1 采用计算字段,只能显示不能输入更新数据库;
2 设置该字段的DisplayValue为:是;否
该方法只能显示,不能输入
3 金宝的方法不详细,不知道怎么用?
4 东部一绝的方法也是只能显示,不能输入
...
希望各位继续伸出援助之手
步骤如下:1:右键单击dbgrid=>columns editor->add all fields
然后选中您需要设置的那一个column,设置它的picklist属性.(把'是''否'添加进去)
步骤二.右键单击table1,fields editor->addallfields 选中您需要设置的那一个字段.在它的GetText事件里面写上:
inherited;
if Sender.AsBoolean = true then
Text := '是'
else if Sender.asboolean =flalse then
Text := '否'
else Text := '';
在它的on settext事件里面写上
inherited;
if Text = '是' then
Sender.Asboolean :=true
else if Text = '否' then
Sender.Asboolean :=false
================over===========
但我建议你干脆改用 Text 类型的字段算了, 何必搞得那么复杂 ..