delphi中dbgrid控件的显示问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 13:11:08
有个小程序,后台用的是SQL sever2000数据库,表中的记录是某人的眼睛度数,字段如下:左眼 ,Sph,矫正,修复,右眼,sph,矫正,修复。想用dbgrid控件实现两行显示一条记录,格式如下:
方向 sph 矫正 修复
左眼 0.4 1.0 1.3
右眼 0.4 1.0 1.3
请问如何实现?高手回答,多谢!

表结构不用改,sql这么写:

select 左眼 as 眼,Sph,校正,修复 from table where ...
union
select 右眼 as 眼,sph,校正,修复 from table where ...

把你的数据库的表的字段修改了,改成如下:字段:方向、SPH、矫正、修复。然后写入两条记录:左眼 0.4 1.0 1.3和右眼 0.4 1.0 1.3。然后用数据控件读出这两条记录,用DBGRID显示即可

假设query里面的数据格式是:
c_dir sph c_col1 c_col2
1 0.4 1.0 1.3
2 0.4 1.0 1.3

你的dbgrid里面把每一列头对应改为
方向 sph 矫正 修复

在query的字段 c_dir 的ongettext里面 写上

if sender.asstring = '1' then
text = '左眼';
if sender.asstring = '2' then
text = '右眼';

这样当你再打开query的时候就会显示你要的东西了

或者你可以用 listview 实现

在dbgrid连接的query中,赋值sql语句。
select 左眼 as 方向,Sph1 as ,矫正1 as 矫正,修复1 as 修复 from table where 人ID=xxx
union
select 右眼 ,sph2,矫正2,修复2 from table where 人ID=xxx