请教怎么在DBGrid中不同记录显示不同的颜色啊小弟我把小弟我的源程序贴上来了,请高手帮忙!
请问如何在DBGrid中不同记录显示不同的颜色啊。我把我的源程序贴上来了,请高手帮忙!急!
在所有工作中需要显示taskid 为1 和0 的记录 但是我们领导要求分别用不同颜色区别,这个俺不会阿。高手来帮忙啊!!谢谢了!!
procedure TForm4.Button1Click(Sender: TObject);
begin
if ComboBox2.Text = '计划内工作 ' then
begin
Query1.Close;
Query1.SQL.Clear;
//showmessage( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' 'and taskid= ' ' ' + '0 ' + ' ' ' ');
Query1.SQL.Add( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' 'and taskid= ' ' ' + '0 ' + ' ' ' ');
Query1.ExecSQL;
Query1.Open;
end
else if ComboBox2.Text = '计划外工作 ' then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' 'and taskid= ' ' ' + '1 ' + ' ' ' ');
Query1.ExecSQL;
Query1.Open;
end
else if ComboBox2.Text = '所有工作 ' then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' ' ');
Query1.ExecSQL;
Query1.Open;
end
else
exit;
end;
------解决方案--------------------
With (Sender as TDBGRID) do
Begin
oldpm:= Canvas.pen.mode;
oldcolor:= Canvas.Brush.color;
Canvas.Brush.color:=newColor;
Canvas.pen.mode:=pmmask;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
Canvas.Brush.color:=oldcolor;
Canvas.pen.mode:=oldpm;
End;
------解决方案--------------------
在DbGrid1的OnDrawColumnCell事件写
if Query1.FieldByName( 'taskid ').AsInteger=1 then
DBGrid1.Canvas.Brush.Color := clBlue
else DBGrid1.Canvas.Brush.Color := clRed;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
在所有工作中需要显示taskid 为1 和0 的记录 但是我们领导要求分别用不同颜色区别,这个俺不会阿。高手来帮忙啊!!谢谢了!!
procedure TForm4.Button1Click(Sender: TObject);
begin
if ComboBox2.Text = '计划内工作 ' then
begin
Query1.Close;
Query1.SQL.Clear;
//showmessage( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' 'and taskid= ' ' ' + '0 ' + ' ' ' ');
Query1.SQL.Add( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' 'and taskid= ' ' ' + '0 ' + ' ' ' ');
Query1.ExecSQL;
Query1.Open;
end
else if ComboBox2.Text = '计划外工作 ' then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' 'and taskid= ' ' ' + '1 ' + ' ' ' ');
Query1.ExecSQL;
Query1.Open;
end
else if ComboBox2.Text = '所有工作 ' then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add( 'select * from ZHAOWEI.BZGZ where workdate = ' ' ' + DateToStr(Self.DateTimePicker1.Date) + ' ' 'and banzu= ' ' ' + Trim(ComboBox1.Text) + ' ' ' ');
Query1.ExecSQL;
Query1.Open;
end
else
exit;
end;
------解决方案--------------------
With (Sender as TDBGRID) do
Begin
oldpm:= Canvas.pen.mode;
oldcolor:= Canvas.Brush.color;
Canvas.Brush.color:=newColor;
Canvas.pen.mode:=pmmask;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
Canvas.Brush.color:=oldcolor;
Canvas.pen.mode:=oldpm;
End;
------解决方案--------------------
在DbGrid1的OnDrawColumnCell事件写
if Query1.FieldByName( 'taskid ').AsInteger=1 then
DBGrid1.Canvas.Brush.Color := clBlue
else DBGrid1.Canvas.Brush.Color := clRed;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);