DBGrid1.OnDrawColumnCell去设置Column
解决方案 »
- 求助判断edit 是否为空 来决定 是否往数据库存数据
- 扩展存储过程返回值的问题
- 用FASTREPORT做套打报表,在报表中有一个合计值,如何固定在报表的某一个位置上
- 关于三层结构的问题
- 急,急,急,我想把dbchart的柱图有原来的6 个 改为10个 该咋弄呀?
- 如何确保用户选择的是Combox下拉列表中的值而不是其它值,最好不要屏蔽用户按键
- 如何使得当用Filter方式查询成功的时候,显示信息为“找到了’
- 16位数据如何位图显示呢?
- infopower 2000与infopower 3000?请高手和版主帮我解答
- (100分)win7连接sqlserver2005数据库问题
- 巨难的SQL语句,非高手误入!
- 有用过xlswrite的朋友吗?请介绍一下它的用法,或提供帮助文档好吗?谢谢
DBGrid1.columns[1].Color:=clGreen;
在DBGrid1.OnDrawColumnCell能设置每一行或每一列的颜色,但具体每一个网格我没有设置过,能给具体的程序看一下吗?望赐教。
DataCol: Integer; Column: TColumn; State: TGridDrawState);begin
//第二行第四列颜色为红色
//修改一下adoquery1为你自己的记录集
//如table,adotable,adodataset,query都可以
if (datacol=3) and (adoquery1.recno=2) then
DbGrid1.Canvas.Brush.color:=rgb(225,0,0); DbGrid1.Canvas.pen.mode:=pmMask;
DbGrid1.DefaultDrawColumnCell (Rect, DataCol, Column, State);end;
在DBGrid1.OnDrawColumnCell能设置每一行或每一列的颜色,但具体每一个网格我没有设置过,能给具体的程序看一下吗?望赐教。
我用的是table.
我所实现的目的是使某一例中的每一个网格的颜色为所设置的颜色,但由于记录随时增加,固实现起来不是很方便。能有很好的方法实现吗?
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
beginwith DbGdMain do
begin
if ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then
begin
Canvas.Font.Color :=ClYellow;
Canvas.Brush.Color :=ClNavy;
end
else
begin
if dsEditSource.DataSet.RecNo mod 2<> 0 then begin {判断当前数据是奇数还是偶数行}
Canvas.brush.Color :=ClWhite; {如果是奇数行,DBGrid背景以白色显示}
end
else begin
Canvas.brush.Color :=$00EAEAEA; {如果是偶数行,DBGrid背景以浅灰色显示}
end; end;
DefaultDrawColumnCell(Rect, DataCol, Column, state );
end;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('size').AsInteger >=40 then
begin
DBGrid1.Canvas.Font.Color := clRed;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
if (Table1.FieldByName('size').AsInteger >=30) and (Table1.FieldByName('size').AsInteger<40) then
begin
DBGrid1.Canvas.Font.Color := clBlue;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
if (Table1.FieldByName('size').AsInteger >=20) and (Table1.FieldByName('size').AsInteger<30) then
begin
DBGrid1.Canvas.Font.Color := clYellow;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
if (Table1.FieldByName('size').AsInteger >=10) and (Table1.FieldByName('size').AsInteger<20) then
begin
DBGrid1.Canvas.Font.Color := clLime;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;end.
Rect: TRect; State: TGridDrawState);
var
x,y:integer;
begin
x:=(acol-stringgrid1.LeftCol)*73+28;
y:=(arow-stringgrid1.TopRow+1)*21+2;
if (acol>0) and (arow>0) and
not ([gdselected]<=state) then
begin
case Form1.Table.fieldstrclist[acol].fieldtype of
'C':
stringgrid1.Canvas.Font.Color:=clblack;
'N':
stringgrid1.Canvas.Font.Color:=clblue;
'L':
stringgrid1.Canvas.Font.Color:=clred;
'D':
stringgrid1.Canvas.Font.Color:=clfuchsia;
end;
stringgrid1.Canvas.TextRect(rect,x,y,
stringgrid1.cells[acol,arow]);
end;
end;
既然已经可以实现控制每个单元格了,那么
加上一些对recno和datacol 的判断就可以啊,比如recno mod 10 ...这些条件.
procedure TForm.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
x,y:integer;
begin
x:=(acol-stringgrid1.LeftCol)*73+28;
y:=(arow-stringgrid1.TopRow+1)*21+2;
case acol of
1:
case arow of
1: ...
2: ...
else ....
end;
2:
... ...
end;
stringgrid1.Canvas.TextRect(rect,x,y,
stringgrid1.cells[acol,arow]);
end;