Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Cambiar el estado de un checkbox insertado en un grid. (https://www.clubdelphi.com/foros/showthread.php?t=15503)

Carlos Arevalo 26-10-2004 00:50:39

Cambiar el estado de un checkbox insertado en un grid.
 
Que tal amigos un saludo para todos la duda que tengo tiene que ver al agregar un tcheckbox a un grid anexo el codigo con el cual agrego el componente el problema es que no logro cambiarle el estado en tiempo de ejecucion me imagino que el problema esta en que el grid siempre esta repintando el objeto y yo no tengo ni idea de como resolver esto.

Gracias de antemano por la ayuda.

Código:

procedure TFormbancos.StringGridmovimientosDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var sCad:String;
    i,n,xindex: integer;
    conciliacheck: TCheckBox;
    control: tcomponent;
begin

      if ACol=7 then // voy a alinear a la derecha la 3ª columna
      if ARow>0 then //No quiero alinear la línea de títulos
      begin
      conciliacheck := TCheckBox.Create(Self);
      control:=findcomponent('conciliacheckx' + IntToStr(arow));
     
      if control=nil then
      begin
      conciliacheck.Name := 'conciliacheckx' + IntToStr(arow);
     
      conciliacheck.Caption :='';

      if StringGridmovimientos.Cells[7,ARow]='F' then
      conciliacheck.Checked := false
      else
      conciliacheck.Checked := true;

      n:=0;
      for i:=1 to acol do n:=n+StringGridmovimientos.ColWidths[i]+1;
      conciliacheck.Left:=n;
      n:=0;
      for i:=1 to arow do n:=n+StringGridmovimientos.RowHeights[i]+1;
      conciliacheck.Top:=n;
      conciliacheck.Width:=13;
      conciliacheck.Height:=13;
      conciliacheck.Parent:=StringGridmovimientos;
      end;
      end;
end;


Carlos Arevalo 26-10-2004 00:53:16

no tomen en cuenta los comentarios de las primeras lineas.

Gracias.

frudolph 26-10-2004 17:11:38

En lugar de un componente checkbox prueba con esto:

Código:


procedure TForm1.StringGridMovimientosDrawCell(
        Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);


const

AState: array[Boolean] of Cardinal = (0, DFCS_CHECKED);

begin

  with TStringGrid(Sender) do

        if (ARow > 0) and (ACol = 7) then
          begin
                Canvas.FillRect(Rect);
                InflateRect(Rect, -2, -2);
                DrawFrameControl(Canvas.Handle, Rect, DFC_BUTTON, DFCS_BUTTONCHECK or AState[Cells[7, Arow] = 'F']);
          end;
end;



Para que cuando el Usuario haga click en el checkbox y se tilde/destilde el mismo programa el Evento "OnMouseUp" del StringGrid con el siguiente código:

Código:


procedure TForm1.StringGridMovimientosMouseUp(
        Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
  AValue: array[Boolean] of String = ('', 'F');
var
  ACol, ARow: Integer;
begin
  with TStringGrid(Sender) do
        begin
          MouseToCell(X, Y, ACol, ARow);
          if (ARow > 0) and (ACol = 7) then
                Cells[ACol, ARow] := AValue[not (Cells[ACol, ARow] = 'F')];
        end;
end;



Carlos Arevalo 27-10-2004 02:05:28

Gracias lo voy a probar y luego comento el resultado

Carlos Arevalo 27-10-2004 02:27:49

Exelente viejo muchas gracias funciona de perla.


La franja horaria es GMT +2. Ahora son las 20:19:15.

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