Como colorir as linhas dentro de uma coluna especifica da grid?

Delphi

19/03/2021

Opa, preciso colorir as linhas de uma colina especifica da grid de acordo com sua situação, quero deixar as linhas em vermelho, azul e verde por exemplo, mas so dentro de uma coluna especifica, so consegui ou colorir toda a linha ou so a coluna com uma unica cor, alguem consegue me ajudar?
Ramboli

Ramboli

Curtidas 0

Melhor post

Emerson Nascimento

Emerson Nascimento

19/03/2021

sempre que possível publique as tentativas já efetuadas.

tente assim, utilizando o evento OnDrawColumnCell:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
	if DataCol = *ColunaDesejada* then
	begin
		if *CondicaoParaCorVerde* then
			TDBGrid(Sender).Canvas.Brush.Color := clGreen
		else
		if *CondicaoParaCorAzul* then
			TDBGrid(Sender).Canvas.Brush.Color := clBlue
		else
		if *CondicaoParaCorVermelha* then
			TDBGrid(Sender).Canvas.Brush.Color := clRed
		else
			TDBGrid(Sender).Canvas.Brush.Color := clWhite;
	end;
	TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
GOSTEI 1

Mais Respostas

Ramboli

Ramboli

19/03/2021

sempre que possível publique as tentativas já efetuadas.

tente assim, utilizando o evento OnDrawColumnCell:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
	if DataCol = *ColunaDesejada* then
	begin
		if *CondicaoParaCorVerde* then
			TDBGrid(Sender).Canvas.Brush.Color := clGreen
		else
		if *CondicaoParaCorAzul* then
			TDBGrid(Sender).Canvas.Brush.Color := clBlue
		else
		if *CondicaoParaCorVermelha* then
			TDBGrid(Sender).Canvas.Brush.Color := clRed
		else
			TDBGrid(Sender).Canvas.Brush.Color := clWhite;
	end;
	TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;



Cara, exatamente isso, so modifiquei algumas coisas pra se encaixar na minha situação, muito obrigado, o senhor sempre m ajudando kk
GOSTEI 0
POSTAR