• 全部
  • 语言基础/算法/系统设计
  • 数据库相关
  • 图形处理/多媒体
  • 网络通信/分布式开发
  • VCL组件开发及应用
  • Windows SDK/API
  • 问答

在线加急等!!!!

leoiv 2004-08-13 10:55:22
程序如下,现在的问题是不管奇行还是偶行,背景色都一样,我需要奇行是一中颜色,偶行是另一中颜色,拜托了,最好在偶的程序上修改偶比较看得懂,拜托拉,有多少分都拿去!
procedure TFrmEditTR_stQuota.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if (FDmdTranMaster as TDmdTR_stQuota).QrySecond.RecNo mod 2 = 1 then
begin
DBGridEh1.Canvas.Brush.Color := $00FF0000;
end
else
begin
DBGridEh1.Canvas.Brush.Color := $00FFFFC2;
end;
DBGridEh1.DefaultDrawColumnCell(rect, datacol, column, state);
end;
...全文
229 点赞 收藏 22
写回复
22 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
panjinfu80 2004-08-13
icol1表示行
if odd(icol1) = true then
StringGrid1.FloatingFooter.Color := clWhite;//奇
else
StringGrid1.FloatingFooter.Color := clRed;//偶
回复
leoiv 2004-08-13
急啊!!!!!!!!!!!!
回复
leoiv 2004-08-13
是不是要先循环先判断一共有多少行?然后如果DEGRID的行是1,就一种颜色,2就另一种颜色
,如果按照这个思路,着段程序应该怎么写?
回复
leoiv 2004-08-13
楼上的,怎么还是没用啊,背景色还是一样的,以下是我从往站上抄来,稍做了修改,你看看有什么问题?procedure TFrmEditTR_stQuota.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState)
var
oldcolor:tcolor;
oldpm:tpenmode;
begin
if DBGridEH1.DataSource.DataSet.RecNo mod 2 = 1 then
DBGridEh1.Canvas.Font.Style := [fsBold];
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
{上面是演示程序的原内容,以下是增加部分}
if DBGridEH1.DataSource.DataSet.RecNo mod 2 = 1 then
begin
oldpm:= MemberGrid.Canvas.pen.mode;
oldcolor:= MemberGrid.Canvas.Brush.color;
DBGridEh1.Canvas.Brush.color:=clyellow;
DBGridEh1.Canvas.pen.mode:=pmmask;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
DBGridEh1.Canvas.Brush.color:=oldcolor;
DBGridEh1.Canvas.pen.mode:=oldpm;
end;

回复
Kerac 2004-08-13
procedure TFrmEditTR_stQuota.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if DBGridEH1.DataSource.DataSet.RecNo mod 2 = 1 then
begin
DBGridEh1.Canvas.Brush.Color := $00FF0000;
end
else
begin
DBGridEh1.Canvas.Brush.Color := $00FFFFC2;
end;
DBGridEh1.DefaultDrawColumnCell(rect, datacol, column, state);
end;
回复
Kerac 2004-08-13
那个窗体继承,继承了Parent的了,所以就不用写了。
回复
leoiv 2004-08-13
楼上的,还是没有用啊procedure TFrmEditTR_stQuota.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
inherited;
if DBGridEH1.DataSource.DataSet.RecNo mod 2 = 1 then
begin
DBGridEh1.Canvas.Brush.Color := $00FF0000;
end
else
begin
DBGridEh1.Canvas.Brush.Color := $00FFFFC2;
end;
DBGridEh1.DefaultDrawColumnCell(rect, datacol, column, state);
end;
回复
leoiv 2004-08-13
我先在是字体颜色不要变,只要背景颜色变呀,如果把DBGridEh1.Canvas.Brush.Color 该成DBGridEh1.Canvas.Font.Color ,只改变了字体的颜色,背景色并没有变
回复
Kerac 2004-08-13
if (FDmdTranMaster as TDmdTR_stQuota).QrySecond.RecNo mod 2 = 1 then

->

if DBGridEH1.DataSource.DataSet.RecNo mod 2 = 1 then


____________________________________________________

弱水三千,我只取一瓢饮
回复
Kerac 2004-08-13
我上边的程序是模版中的一段程序,已经用了很久,具体的如下:

private
{ Private declarations }
FArray : Array of String;
FRecord_Str: String;
FDBGird: TDBGridEH;
Procedure MoveRecord(vDataSet : TDataSet ; vOption :TDBOption );
Function IsSaveState(vDataSet : TDataSet):Boolean;
Function GetDataDec :TStrings;
Function GetDataValue(vCBX : TCustomComboBox) : TStrings;
Function GetFieldName(vCBX : TCustomComboBox) : String;
Procedure SaveEvent;
Procedure EditEvent;
Procedure AddEvent;
Procedure CancelEvent;
Procedure DeleteEvent;
Procedure QueryEvent(vDataSet : TADOQuery; vSQLStr ,vFieldName ,
vFieldValue , vCon : String ; vInt : Integer = 0);
procedure DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public
{ Public declarations }
TempDataSet , FADOQuery : TADOQuery;
FSQLStr : String;
FDBGrid : TDBGridEH;
~~~~~~~~~~~~~~~~~~~~~


procedure TTemplteFrm.DBGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if gdSelected in State then
Exit;
if TDBGridEh(Sender).DataSource.DataSet.RecNo mod 2 = 1 then
(Sender as TDBGridEh).Canvas.Brush.Color:=clwhite
else
(Sender as TDBGridEh).Canvas.Brush.Color:=$00F2F2F2;
(Sender as TDBGridEh).DefaultDrawColumnCell(Rect,Datacol,Column,State);
end;




调用:
procedure TDataOutputFrm.Link;
begin
inherited;
FADOQuery := DataModuleFrm.PTCLXSCKSet;
SetDBGrid(PTCLCKDBGrid,DataModuleFrm.PTCLXSCKDS);
SetSQLStr('Select * From CommonOutput where CoState = ''WB'' and CoType = ''PT''');



PTCLCKDBGrid.ClassType Is TDBGridEH
回复
Randomize 2004-08-13
if (FDmdTranMaster as TDmdTR_stQuota).QrySecond.RecNo mod 2 = 1 then
begin
DBGridEh1.Canvas.Brush.Color := $00FF0000;
問題就是上面用(FDmdTranMaster as TDmdTR_stQuota).QrySecond
而下面用的則是DBGriD驢唇對不上馬嘴
回复
thunderniao 2004-08-13
DBGridEh1.Canvas.Brush.Color := $00FF0000;
--------------------------------------------------
应该是DBGridEh1.Canvas.Font.Color
回复
leoiv 2004-08-13
以上各位的办法我都试过为什么还是这样呢???
回复
Kerac 2004-08-13
procedure TTemplteFrm.DBGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if gdSelected in State then
Exit;
if TDBGridEh(Sender).DataSource.DataSet.RecNo mod 2 = 1 then
(Sender as TDBGridEh).Canvas.Brush.Color:=clwhite
else
(Sender as TDBGridEh).Canvas.Brush.Color:=$00F2F2F2;
(Sender as TDBGridEh).DefaultDrawColumnCell(Rect,Datacol,Column,State);
end;


____________________________________________________

弱水三千,我只取一瓢饮
回复
梅青松 2004-08-13
除非
if (FDmdTranMaster as TDmdTR_stQuota).QrySecond.RecNo mod 2 = 1 then
有问题
回复
fei19790920 2004-08-13
procedure TFrmEditTR_stQuota.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if (FDmdTranMaster as TDmdTR_stQuota).QrySecond.RecNo mod 2 = 1 then
DBGridEh1.Canvas.Brush.Color := $00FF0000
else
DBGridEh1.Canvas.Brush.Color := $00FFFFC2;
end;
回复
jinjazz 2004-08-13
没有问题,DBGridEh1也应该一样吧
回复
jinjazz 2004-08-13
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DBGrid1.DataSource.DataSet.RecNo mod 2 = 1 then
begin
DBGrid1.Canvas.Brush.Color := $00FF0000;
end
else
begin
DBGrid1.Canvas.Brush.Color := $00FFFFC2;
end;
DBGrid1.DefaultDrawColumnCell(rect, datacol, column, state);
end;
回复
leoiv 2004-08-13
我先在知道为什么你们可以了,因为版本的问题,我是5。0版本的,所以运行不到这个效果
回复
luckzhangs 2004-08-13
if DBGridEh1.DataSource.DataSet.RecNo mod 2=0 then
(Sender as TDBGridEh).Canvas.Brush.Color:=clRed
else
(Sender as TDBGridEh).Canvas.Brush.Color:=clGreen;
DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
这个可以的,我试过才发上来的
回复
发帖
Delphi
创建于2007-08-02

4873

社区成员

Delphi 开发及应用
申请成为版主
帖子事件
创建了帖子
2004-08-13 10:55
社区公告
暂无公告