Ver Mensaje Individual
  #8  
Antiguo 28-07-2016
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.
Cita:
Empezado por santiago14 Ver Mensaje
...
Lo explico, la grilla tiene la fila seleccionada en un color (azul por ejemplo), y la celda actual en otro color (amarillo...) ...
Te pongo un ejemplo con otra opción, fijate si te sirve:

Código Delphi [-]
...
interface

uses ..., Mask;

type
  TStringGrid = class(Grids.TStringGrid)
  protected
    function CreateEditor: TInplaceEdit; override;
  end;

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
  public
  end;

...

implementation

const
  COLORHIGH = clYellow;
  COLORLOW  = clBlue;

{ TStringGrid (Respetar los colores en la edición) }
function TStringGrid.CreateEditor: TInplaceEdit;
begin
  Result := inherited CreateEditor;
  if Focused then
    TMaskEdit(Result).Color := COLORHIGH
  else
    TMaskEdit(Result).Color := COLORLOW;
end;

var
  LastRowSel: Integer;

// cargar algunos datos en el StringGrid
procedure TForm1.FormCreate(Sender: TObject);
var
  c, r: Integer;
  sg: TStringGrid;
begin
  sg := StringGrid1;
  sg.Rows[0].CommaText := 'NRO_OP,TITULO_AVISO,TEXTO_AVISO';
  
  for c := sg.FixedCols to sg.ColCount-1 do
  begin
    sg.ColWidths[c] := 120;
    for r := sg.FixedRows to sg.RowCount -1 do
    begin
      sg.Cells[c, r] := Format('%.12d',[c+r]);
      sg.Objects[c, r] := TObject(sg.Color);   // color por defecto: El del StringGrid !
    end;
  end;
  sg.ColWidths[1] := 300;
  LastRowSel := sg.Row;
  
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  sg: TStringGrid;
begin
  sg := TStringGrid(Sender);
  if not (gdFixed in State) then
  begin
    sg.Canvas.Brush.Color := TColor(sg.Objects[ACol, ARow]);
    sg.Canvas.FillRect(Rect);
    sg.Canvas.TextOut(Rect.Left+2, Rect.Top+2, sg.Cells[Acol,ARow]);
  end;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
var
  sg: TStringGrid;
  c: Integer;
begin
  sg := TStringGrid(Sender);
  // anterior línea seleccionada en el color del StringGrid
  for c := sg.FixedCols to sg.ColCount - 1 do
    sg.Objects[c, LastRowSel] := TObject(sg.Color);

  // nueva linea seleccionada
  for c := sg.FixedCols to sg.ColCount - 1 do
    if c = aCol then
      sg.Objects[c, ARow] := TObject(COLORHIGH)
    else
     sg.Objects[c, ARow] := TObject(COLORLOW);

  LastRowSel := ARow; // ultima línea = nueva línea
end;

end.

Salida:


Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita