GARANTIR DESCONTO

Fórum ChekListBox com checkbox invisivel - Tem como? #343269

13/07/2007

0

Pessoal, ta dificil de usar o CheckListBox e deixar somente os campos que eu preciso com o checked visible e marcados tambem.

No caso se eu usar o checklistbox todos que estao na lista ficam com o checkbox visible, e eu precisaria apenas mostrar os checkbox nos campos que estao em vermelho, cfe. o codigo abaixo:

var Func, Empresa : string; begin fGerarFolhaMes.LbLista.Clear; //-Limpando ListBox dm.qRestrFolha.DisableControls; //desativa os controles try dm.qRestrFolha.First; Empresa := #121415; while not dm.qRestrFolha.Eof do begin if Empresa <> dm.qRestrFolha.fieldbyname(´id_EMPRESA´).AsString then begin if Empresa <> 121415 then fGerarFolhaMes.LbLista.Items.Add(´´); Empresa := dm.qRestrFolha.fieldbyname(´id_EMPRESA´).AsString ; if dm.qEmpresa.Locate(´id_EMPRESA´, Empresa, []) then Func := dm.qEmpresa.fieldbyname(´empresa´).AsString else Func := ´Empresa não cadastrada´; {pelo q entendi seria necessário} fGerarFolhaMes.LbLista.Items.Add(´================================================================================´); fGerarFolhaMes.LbLista.Items.Add(´Data que foi gerada a Folha : ´ + ´ - ´ + DateToStr(now) + ´ - ´ + TimeToStr(now)); fGerarFolhaMes.LbLista.Items.Add(´================================================================================´); fGerarFolhaMes.LbLista.Items.Add(Empresa + ´ - ´ + Func); fGerarFolhaMes.LbLista.Items.Add(´================================================================================´); Func := #121415; end; if Func <> dm.qRestrFolha.fieldbyname(´id_func´).AsString then begin if Func <> 121415 then fGerarFolhaMes.LbLista.Items.Add(´********************************************************************************´); Func := dm.qRestrFolha.fieldbyname(´id_func´).AsString; fGerarFolhaMes.LbLista.Items.Add(Func + ´ - ´ + dm.qRestrFolha.fieldbyname(´nome´).AsString); fGerarFolhaMes.LbLista.Items.Add(´Salario Base para Calculos: ´ + dm.qRestrFolha.fieldbyname(´salario´).AsString); fGerarFolhaMes.LbLista.Items.Add(´Proventos/Descontos Ativos:´); fGerarFolhaMes.LbLista.Items.Add(´================================================================================´); end; //--Passando a listagem para o ListBox [color=red:b3a501f23b]fGerarFolhaMes.LbLista.Items.Add(dm.qRestrFolha.fieldbyname(´descricao´).AsString + ´ - ´ + dm.qRestrFolha.fieldbyname(´quantia´).asString + dm.qRestrFolha.fieldbyname(´formula´).AsString);[/color:b3a501f23b] dm.qRestrFolha.Next; //passa pra frente end; finally dm.qRestrFolha.EnableControls; //ativa os controles end; {creio q deve ativar qdo concluir} fGerarFolhaMes.LbLista.Items.Add(´********************************************************************************´); fGerarFolhaMes.ShowModal; end.


O nome do checklistbox eh lbLista e estou passando valores de uma tabela para este checklistbox.

Mais como disse precisaria apenas que somente os campos que aparecem em vermelhos ficassem com o checkbox = true e visible = true o resto dos dados na lista o checkbox tem que ficar invisivel.


Adriano_servitec

Adriano_servitec

Responder

Posts

14/07/2007

Adriano_servitec

Se os campos no checklistbox fossem fixo poderia fazer assim:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, CheckLst;

type
  TForm1 = class(TForm)
    CheckListBox1: TCheckListBox;
    procedure FormCreate(Sender: TObject);
    procedure CheckListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; cState: TOwnerDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
CheckListBox1.ItemEnabled[0] := False;
CheckListBox1.ItemEnabled[3] := False;
CheckListBox1.ItemEnabled[5] := False;
end;

var
  _FCheckWidth : Integer = -100;
  _FCheckHeight: Integer = 0;

function GetCheckSize : TPoint;
begin
  if _FCheckWidth = -100 then
  begin
  with TBitmap.Create do
    try
      Handle := LoadBitmap(0, PChar(32759));
      _FCheckWidth := Width div 4;
      _FCheckHeight := Height div 3;
    finally
      Free;
    end;
  end;
  Result.x := _FCheckWidth;
  Result.y := _FCheckHeight;
end;


procedure DrawCheck(Canvas : TCanvas; R: TRect; AState: TCheckBoxState; Flat : Boolean);
var
  DrawState: Integer;
  DrawRect: TRect;
  OldBrushColor: TColor;
  OldBrushStyle: TBrushStyle;
  OldPenColor: TColor;
  Rgn, SaveRgn: HRgn;
begin
  SaveRgn := 0;
  DrawRect.Left := R.Left + (R.Right - R.Left - GetCheckSize.x) div 2;
  DrawRect.Top := R.Top + (R.Bottom - R.Top - GetCheckSize.x) div 2;
  DrawRect.Right := DrawRect.Left + GetCheckSize.x;
  DrawRect.Bottom := DrawRect.Top + GetCheckSize.y;
  case AState of
    cbChecked:
      DrawState := DFCS_BUTTONCHECK or DFCS_CHECKED;
    cbUnchecked:
      DrawState := DFCS_BUTTONCHECK;
    else // cbGrayed
      DrawState := DFCS_BUTTON3STATE or DFCS_CHECKED;
  end;

  with Canvas do
  begin
    if Flat then
    begin
      { Remember current clipping region }
      SaveRgn := CreateRectRgn(0,0,0,0);
      GetClipRgn(Handle, SaveRgn);
      { Clip 3d-style checkbox to prevent flicker }
      with DrawRect do
        Rgn := CreateRectRgn(Left + 2, Top + 2, Right - 2, Bottom - 2);
      SelectClipRgn(Handle, Rgn);
      DeleteObject(Rgn);
    end;
    DrawFrameControl(Handle, DrawRect, DFC_BUTTON, DrawState);
    if Flat then
    begin
      SelectClipRgn(Handle, SaveRgn);
      DeleteObject(SaveRgn);
      { Draw flat rectangle in-place of clipped 3d checkbox above }
      OldBrushStyle := Brush.Style;
      OldBrushColor := Brush.Color;
      OldPenColor := Pen.Color;
      Brush.Style := bsClear;
      Pen.Color := clBtnShadow;
      with DrawRect do
        Rectangle(Left + 1, Top + 1, Right - 1, Bottom - 1);
      Brush.Style := OldBrushStyle;
      Brush.Color := OldBrushColor;
      Pen.Color := OldPenColor;
    end;
  end;
end;

procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; cState: TOwnerDrawState);
var
  R: TRect;
  ACheckWidth: Integer;
begin
  with CheckListBox1 do
  begin
    ACheckWidth := GetCheckSize.x + 2;

    R := Rect;

    if not UseRightToLeftAlignment then
    begin
      R.Right := Rect.Left;
      R.Left := R.Right - ACheckWidth;
    end
    else
    begin
      R.Left := Rect.Right;
      R.Right := R.Left + ACheckWidth;
    end;

    if ItemEnabled[Index] then
    begin
      if Index < Items.Count then
        DrawCheck(Canvas, R, State[Index], Flat);
    end else
    begin
      ACheckWidth := Canvas.Brush.Color;
      Canvas.Brush.Color := Color;
      Canvas.FillRect(R);
      Canvas.Brush.Color := ACheckWidth;
    end;

    Canvas.FillRect(Rect);
    if odSelected in cState then
      Canvas.Font.Color := clHighlightText
    else
    Canvas.Font.Color := Font.Color;

    if Index < Items.Count then
    begin
      if not UseRightToLeftAlignment then
        Inc(Rect.Left, 2)
      else
        Dec(Rect.Right, 2);

      DrawText(Canvas.Handle, PChar(Items[Index]), Length(Items[Index]), Rect,
        DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX));
    end;
  end;
end;

end. 


Soh que eu nao sei aonde vao ficar estas linhas
CheckListBox1.ItemEnabled[0] := False;
CheckListBox1.ItemEnabled[3] := False;
CheckListBox1.ItemEnabled[5] := False;


Alguem poderia me ajudar?

Grato Adriano


Responder

Gostei + 0

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

Aceitar