Fórum Dbgrid com campo checkbox .. HELP URGENTE #171792

27/07/2003

0

preciso fazer um DBgrid que o campo que será permitido acesso deve ser um checkbox .... como fazer ???


Carlos Jatai

Carlos Jatai

Responder

Posts

27/07/2003

Aroldo Zanela

Colega,

Uma idéia:

1) add to the DataSet Calculated Field : char[1]; 2) Show it on the grid instead of Boolean with WinDing font; 3) Use OnCellClick event to toggle boolean field. 4) Set DataSet.OnCalcFields event to assign calculated field to a symbol that is draw as an empty|marked checkbox in WinDing font, according to value of Boolean field.


Outra

Next code will draw a checkbox in specified rect with specified state:

procedure DrawCheckBox(R: TRect; AState: TCheckBoxState; al: TAlignment);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
  case AState of
    cbChecked: DrawState := DFCS_BUTTONCHECK or DFCS_CHECKED;
    cbUnchecked: DrawState := DFCS_BUTTONCHECK;
    else // cbGrayed
      DrawState := DFCS_BUTTON3STATE or DFCS_CHECKED;
  end;
  case al of
    taRightJustify: begin
                      DrawRect.Left := R.Right - FCheckWidth;
                      DrawRect.Right := R.Right;
                    end;
    taCenter: begin
                DrawRect.Left := R.Left + (R.Right - R.Left - FCheckWidth)
div 2;
                DrawRect.Right := DrawRect.Left + FCheckWidth;
              end;
  else // taLeftJustify
    DrawRect.Left := R.Left;
    DrawRect.Right := DrawRect.Left + FCheckWidth;
  end;
  DrawRect.Top := R.Top + (R.Bottom - R.Top - FCheckWidth) div 2;
  DrawRect.Bottom := DrawRect.Top + FCheckHeight;

   DrawFrameControl(Canvas.Handle, DrawRect, DFC_BUTTON, DrawState);
end;



Mais fácil:

So just call this procedure from OnDrawCell event. It work for me in freeware TSMDBGrid (see my site) -- With best regards, Mike Shkolnik EMail: mshkolnik@scalabium.com http://www.scalabium.com



Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar