有这样一个问题(10分)

  • 主题发起人 ifcansee
  • 开始时间
I

ifcansee

Unregistered / Unconfirmed
GUEST, unregistred user!
我用query1查询一个表
sql语句为select a,b,c from t1.dbf得到的结果在dbgrid1中显示如下
a b c
1 23 55
1 43 67
1 12 98
2 43 55
2 55 67
3 65 98
1 .. ..
2 .. ..
1 .. ..
3 .. ..
. .. ...
我想让所有字段a的值为1的显示为“甲“,为2的显示为“乙“,为3的显示为“丙“
也就是最终结果是
a









丙。。。。。。
该怎么做,我用计算字段的方法好像不行
 
没有人会吗?
 
如果换成TStringGrid比较容易实现

for i:=0 to StringGrid1.ColumnCount-1 do
for j:=0 to StringGrid1.rowCount-1 do
begin
if stringGrid1.cell[i,j]='1' then
stringGrid1.cell[i,j]=‘甲';
if stringGrid1.cell[i,j]='2' then
stringGrid1.cell[i,j]='乙';
end
 
增加一個計算字段.Field1,DbGrid增加一列連結到Field1
在DataSet的OnCalcFields事件中
if DataSet.FieldByName('a').AsString='1' then
DataSet.FieldByName('Field1').AsString='甲'

 
我就是用了一个计算字段c,然后在query1的oncalcfields事件中加上了
if query1a.asinteger=1 then query1c.asstring:='甲';
不过运行后怎么c字段下是空白的
 
1.不要用field.asString或者field.AsInteger,用FieldByName('').AsXXX
2.跟蹤調試.
 
stringgrid只能显示string字段吗?这个控件是delphi自带吗?我怎么找不到
 
我用fieldbyname.asxxx试了一下,解决了,但fieldbyname.asxxx和query1a.asxxx有什么
差别呢?
谢谢
 
具體我也說不清.少用FieldName.AsXXX就是了
 
没什么区别。
 
TsringGrid这个东东你都不知道啊?
在前面几个东东好似在standare或者那个addition那里啊
这个简单一个东东都要这么麻烦!!!!!!!!!!
TstringGrid就是没有dataset相连的DBgrid啦,几好的啦
考虑下吧
 
顶部