用普通DBGRID也可实现:
1.定义一变量nowClass,初始值为空
2.相应查询中必须加order by 分类 取出数据
3.在DBGrid1DrawColumnCell中加代码:
if (column.fieldname="分类"
then
begin
if (nowClass<>Grid1.dataset.fieldbyname('分类').asstring ) then
begin
Dbgrid1.Canvas.Brush.Color :=clyellow;
Dbgrid1.Canvas.FillRect(rect);
Dbgrid1. Canvas.font.color := clblack;
end
else
begin
Dbgrid1.Canvas.Brush.Color :=clwhite;
Dbgrid1.Canvas.FillRect(rect);
Dbgrid1. Canvas.font.color := clwhite;
end;
Nowclass:=DBGrid1.dataset.fieldbyname('分类').asstring;
end
else
begin
Dbgrid1..Canvas.Brush.Color :=clwhite;
Dbgrid1.Canvas.FillRect(rect);
Dbgrid1..Canvas.font.color := clblack;
end
Dbgrid1.DefaultDrawcolumnCell(rect,datacol,column,state);