Ver Mensaje Individual
  #4  
Antiguo 28-04-2018
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.

Fijate si este ejemplo es similar a lo que buscas hacer:
Código Delphi [-]
...
type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    btCopy: TButton;
    ListBox1: TListBox;
    btClear: TButton;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure btCopyClick(Sender: TObject);
    procedure btClearClick(Sender: TObject);
  private
    procedure ClearSGSelection;
  public
  end;

var
  Form1: TForm1;

implementation {$R *.dfm}

procedure TForm1.ClearSGSelection;
var
  c: Integer;
  r: Integer;
begin
  for r := StringGrid1.FixedCols to StringGrid1.RowCount-1 do
    for c := StringGrid1.FixedRows to StringGrid1.ColCount-1 do
      StringGrid1.Objects[c,r] := Pointer(0);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  c: Integer;
  r: Integer;
begin
  ClearSGSelection;
  for r := StringGrid1.FixedCols to StringGrid1.RowCount-1 do
    for c := StringGrid1.FixedRows to StringGrid1.ColCount-1 do
      StringGrid1.Cells[c,r] := IntToStr(c+r);
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  SG: TStringGrid;
  pt: TPoint;
  CellOnOff : Boolean;
begin
  if ssCtrl in Shift then
  begin
    SG := TStringGrid(Sender);
    SG.MouseToCell(X, Y, pt.X, pt.Y);
    CellOnOff := not Boolean(SG.Objects[pt.X, pt.Y]);
    SG.Objects[pt.X, pt.Y] := Pointer(Integer(CellOnOff));
  end;
end;


procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  SG: TStringGrid;
begin
  SG := Sender as TStringGrid;
  if Boolean(sg.Objects[ACol, ARow]) then
  begin
    SG.Canvas.Brush.Color := clActiveCaption;
    SG.Canvas.Brush.Style := bsSolid;
    SG.Canvas.FillRect(Rect);
    InflateRect(rect, -2, -2);
    sg.Canvas.TextRect(Rect, Rect.left, Rect.top, SG.Cells[acol, arow]);
  end;
end;

procedure TForm1.btCopyClick(Sender: TObject);
var
  c: Integer;
  r: Integer;
begin
  for r := StringGrid1.FixedCols to StringGrid1.RowCount-1 do
    for c := StringGrid1.FixedRows to StringGrid1.ColCount-1 do
      if Boolean(StringGrid1.Objects[c,r]) then
         ListBox1.Items.Add(StringGrid1.Cells[c,r]);
end;

procedure TForm1.btClearClick(Sender: TObject);
begin
  ListBox1.Items.Clear;
  ClearSGSelection;
end;
end.

Salida:


Saludos
__________________
Daniel Didriksen

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

Última edición por ecfisa fecha: 29-04-2018 a las 00:10:17.
Responder Con Cita