Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 28-04-2018
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 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
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
StringGrid problemas al seleccionar celdas danielmj Varios 3 29-10-2014 19:38:58
Seleccionar fila con clic derecho en StringGrid DSK25 C++ Builder 2 19-10-2012 01:28:05
como seleccionar las celdas de un dbgrid con el mouse jjaen26 OOP 0 13-10-2011 17:48:45
Como seleccionar un rango de filas en un DBGrid? YAlvarez OOP 1 09-05-2008 19:54:47
¿como seleccionar columnas, StringGrid? TURING Varios 3 25-11-2005 21:15:54


La franja horaria es GMT +2. Ahora son las 14:14:51.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi