Fórum Colorir linha no DBGrid sem utilizar a propiedade ROWSELECT #356746
07/04/2008
0
Obrigado.
Joaohenriquemf
Curtir tópico
+ 0Posts
08/04/2008
Edineidaniel
Seguinte lembro que isso saiu em uma das edições da Clube Delphi... Tirei alguns exemplos, sobre formatação de fonte e tal´s, quem sabe vc pode alterar para sua necessidade...
GridExibicao.Columns.Items[i].Title.Font.Color:=ClBlack;//Cor da Fonte
GridExibicao.COLUMNS.ITEMS[I].TITLE.FONT.STYLE := [];//Cot da Fonte
GridExibicao.Columns.Items[i].Title.Color:=clBtnFace;//Cor do Fundo do Titulo Normal
Column.Title.Color :=clSilver;//Cor do Fundo do Titulo Selecionado
COLUMN.TITLE.FONT.STYLE := [FSBOLD];
Column.Title.Font.Color:=ClBlue;
Column.Font.color:=clTeal;
Col:= GridExibicao.Columns[Column.Index].Index;
GridExibicao.Columns.Items[i].Font.color:=ClBlack;
t+
Edinei
Gostei + 0
08/04/2008
Joaohenriquemf
amigo, no caso queria fazer como o ROWSELECT do grid mesmo, no caso pintar a linha selecionada.Porém o ROWSELECT deixa o grid readOnly, estou fazendo assim, mais tem momentos que o cliente dataSet manda o [b:b0b79b2b20]´RECNO´[/b:b0b79b2b20] de forma estranha
procedure TfrmPDV.DBGItensDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin DBGItens.Canvas.Brush.Color := clWhite; DBGItens.Canvas.Font.Color := clBlack; if (DGBItens.Row = cdsItens.RecNo) then DBGItens.Canvas.Brush.Color := clBlue; DBGItens.DefaultDrawDataCell(Rect, DBGItens.Columns[datacol].Field, State); end;
obs:A propiedade ´[b:b0b79b2b20]ROW[/b:b0b79b2b20]´ é do JvDBGrid do JEDI
Gostei + 0
11/04/2008
Tonidavi2004
[color=red:70f61fdc9b]amigo, no caso queria fazer como o ROWSELECT do grid mesmo, no caso pintar a linha selecionada.Porém o ROWSELECT deixa o grid readOnly, estou fazendo assim, mais tem momentos que o cliente dataSet manda o ´RECNO´ de forma estranha[/color:70f61fdc9b]
Se vc não desistiu, vou colocar aqui o código que eu consegui. Infelizmente não tive tempo para melhorá-lo, mas vc pode fazê-lo. Só está funcionando ao clicar na célula.
unit UColorirDBGrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, StdCtrls, Grids, DBGrids;
type
THackDBGrid = class(TDBGrid);
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
procedure DBGrid1CellClick(Column: TColumn);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
Row, AColMaior, AColMenor: integer;
begin
Row := THackDBGrid(DBGrid1).Row;
AColMaior := THackDBGrid(DBGrid1).Col;
AColMenor := THackDBGrid(DBGrid1).Col;
while AColMaior <= Pred(THackDBGrid(DBGrid1).ColCount) do
begin
DBGrid1DrawColumnCell(DBGrid1, THackDBGrid(DBGrid1).CellRect(AColMaior, Row), (AColMaior - 1), DBGrid1.Columns.Items[(AColMaior - 1)], [gdSelected, gdFocused]);
Inc(AColMaior);
end;
while AColMenor >= THackDBGrid(DBGrid1).FixedCols do
begin
DBGrid1DrawColumnCell(DBGrid1, THackDBGrid(DBGrid1).CellRect(AColMenor, Row), (AColMenor - 1), DBGrid1.Columns.Items[(AColMenor - 1)], [gdSelected, gdFocused]);
Dec(AColMenor);
end;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if State = [gdSelected, gdFocused] then
begin
DBGrid1.Canvas.Brush.Color := clBlue;
DBGrid1.Canvas.Font.Color := clWindow;
end;
DBGrid1.DefaultDrawDataCell(Rect, DBGrid1.Columns[DataCol].Field, State);
end;
end.
Gostei + 0
11/04/2008
Tonidavi2004
unit UColorirDBGrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, StdCtrls, Grids, DBGrids;
type
THackDBGrid = class(TDBGrid);
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
procedure DBGrid1CellClick(Column: TColumn);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
Row, ACol: integer;
begin
Row := THackDBGrid(DBGrid1).Row;
ACol := 1;
while ACol <= Pred(THackDBGrid(DBGrid1).ColCount) do
begin
DBGrid1DrawColumnCell(DBGrid1, THackDBGrid(DBGrid1).CellRect(ACol, Row), (ACol - 1), DBGrid1.Columns.Items[(ACol - 1)], [gdSelected, gdFocused]);
Inc(ACol);
end;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if State = [gdSelected, gdFocused] then
begin
DBGrid1.Canvas.Brush.Color := clBlue;
DBGrid1.Canvas.Font.Color := clWindow;
end;
DBGrid1.DefaultDrawDataCell(Rect, DBGrid1.Columns[DataCol].Field, State);
end;
end.
Gostei + 0
08/05/2008
Vanderley Rocha
crie uma variável pública to tipo String.
Cursor : String;
No evento AfterScroll da tabela mostrada no DBGrid coloque o Seguinte:
Cursor := Tabela.BookMark;
no Evento onDrawDataCell do DBGrid coloque:
if Cursor = tabela.BookMark then
DBGrid.Canvas.Brush.Color := CorQueVcQuiser;
Dbgrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)