I'll go first of all for the image to see if anyone knows how to fix this.
Howtoseewhenthelineisselected,thetestogetsduplicatedandpreventstheinformationfrombeingdisplayed.I'musingDelphi10.1Berlin.IhavethissamecodeinDelphi7andeverythingworksfine...(Strange)
Intheevent"dbgCentroCustoDrawColumnCell" I align the text of the Cost Center and Description columns
procedure TfrmCentroCusto.dbgCentroCustoDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Format: integer; {poderá utilizar:FmtCentered,FmtLeft,FmtRight,taLeftJustify,taCenter,taRightJustify}
R: TRect;
begin
Format := 0;
{$REGION ' CODIGO CENTRO CUSTO '}
if (dbgCentroCusto.Columns[datacol].Field.FieldName = 'CODIGO_CENTRO_CUSTO') then
begin// 1º Nivel
if (Copy(DataModuleGeral2.qryPesquisaCentroCustoCODIGO_CENTRO_CUSTO.AsString,4,8) = '00.00') then
begin
R := Rect;
Format := FmtLeft;
dbgCentroCusto.Canvas.FillRect(Rect);
dbgCentroCusto.Canvas.Font.Style := [fsbold];
end else// 2º Nivel
if (dbgCentroCusto.Columns[datacol].Field.FieldName = 'CODIGO_CENTRO_CUSTO') and ((Copy(DataModuleGeral2.qryPesquisaCentroCustoCODIGO_CENTRO_CUSTO.AsString,4,8)>'00')and(Copy(DataModuleGeral2.qryPesquisaCentroCustoCODIGO_CENTRO_CUSTO.AsString,7,8)='00'))then
begin
R := Rect;
Format := FmtCentered;
dbgCentroCusto.Canvas.FillRect(Rect);
dbgCentroCusto.Canvas.Font.Style := [fsbold];
dbgCentroCusto.Columns[0].Alignment := taCenter;
end else // 3º Nivel
if (dbgCentroCusto.Columns[datacol].Field.FieldName='CODIGO_CENTRO_CUSTO') then
begin
R := Rect;
Format := FmtRight;
dbgCentroCusto.Canvas.FillRect(Rect);
dbgCentroCusto.Columns[0].Alignment := taRightJustify;
end;
// Aplica as mudanção no visual da Grid: Conteudo do Celula Tamanho do Conteudo do Celula Alinhamento
DrawText(dbgCentroCusto.Canvas.Handle, PChar(' '+Column.Field.AsString+' '), Length (' '+Column.Field.AsString+' '), R, Format);
end;
This is only a part because for the Description field it repeats the same as above ...