请教:如何动态控制DBGrid中行的颜色?(100分)

  • 主题发起人 主题发起人 weiyuan99
  • 开始时间 开始时间
W

weiyuan99

Unregistered / Unconfirmed
GUEST, unregistred user!

本人做了一个权限管理模块,用DBGrid来显示用户的权限信息,主要字段如下:

模块编码(ModCode),菜单编码(MenuCode),浏览(WBrowse),维护(WEdit),审核(WCheck)

编码规则举例如下:
ModCode,MenuCode,WBrowse,WEdit,WCheck
01 0101 1 0 0
01 0102 1 0 0
01 0103 1 1 0

02 0201 1 0 0
02 0202 1 0 0
02 0203 1 0 0

03 0301 1 0 0
......

我想同一模块用一种颜色,不同模块颜色间隔(共两种颜色),模块边码不一定连续(由小到大),

可能是:01,03,04,09,10;03,04,06,07,15;......

现在控制DBGrid第一次画的时候,达到要求,但是,重画时,颜色就会混乱,不知

如何控制,我得代码如下:

//---------------------------------------------------------------------------
private: // User declarations
int tt; //test
void __fastcall TFormUserWarrant::DBGrdEhWarrantInfoDrawColumnCell(
TObject *Sender, const TRect &Rect, int DataCol, TColumnEh *Column,
TGridDrawState State)
{
TColor RowColor;
RowColor = DBGrdEhWarrantInfo->Canvas->Brush->Color;
if((RowColor == clTeal)||(RowColor == clInfoBk)) return;
if(AQryWarrantInfo->Fields->FieldByName("MOD_SMID")->AsString != "")
{
sCurModNo = AQryWarrantInfo->Fields->FieldByName("MOD_SMID")->AsString;//当前模块编码
}
if(sModNo != sCurModNo)
{
tt = tt + 1;
}
DBGrdEhWarrantInfo->Canvas->Brush->Style = bsClear;
DBGrdEhWarrantInfo->Canvas->Font->Color = clBlack;
if(tt%2)
{
DBGrdEhWarrantInfo->Canvas->Brush->Color = clTeal;
}
else
{
DBGrdEhWarrantInfo->Canvas->Brush->Color = clInfoBk;
}
sModNo = sCurModNo;
DBGrdEhWarrantInfo->DefaultDrawColumnCell(Rect, DataCol, Column, State);
String sMsg = "Paint!";
}
//---------------------------------------------------------------------------
 
procedure TQryResult_F.DBGrid2DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if qrypara.fieldbyname('dot_time').asinteger=ndot_time then
begin
dbgrid2.Canvas.Font.Color:=clblue;
dbgrid2.DefaultDrawColumnCell(rect,datacol,column,state);
end else
begin
dbgrid2.Canvas.Font.Color:=clblack;
dbgrid2.DefaultDrawColumnCell(rect,datacol,column,state);
end;


end;

procedure TQryResult_F.QryparaAfterScroll(DataSet: TDataSet);
begin
ndot_time:=qrypara.fieldbyname('dot_time').asinteger;
dbgrid2.Invalidate;
end;

 
还是没法控制DBGrid的颜色,不过倒是提醒我,DBGrid重画与QueryAfterScroll事件密切相关,谢谢
 
虽然没有完全达到我想要的效果,这种效果也蛮不错的,谢了!
 

Similar threads

I
回复
0
查看
748
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
774
import
I
后退
顶部