Recent

Author Topic: [SOLVED] Disabling a CheckListBox  (Read 1082 times)

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
[SOLVED] Disabling a CheckListBox
« on: December 10, 2019, 02:40:34 pm »
Dear ALL,

How do I disable a CheckListBox, so that a user cannot change the state of each box?

I tried this:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.StatesListBoxMouseDown(Sender: TObject;
  2.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  3. begin
  4.    Abort;
  5. end;
  6.  

and this:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.StatesListBoxKeyPress(Sender: TObject; var Key: char);
  2. begin
  3.    if (Key = #13) or (Key = #32) then Abort;
  4. end;

but none of them worked.

Setting

Code: Pascal  [Select][+][-]
  1. CheckListBox1.Enabled := False;
  2.  

is not a good solution either because (at least under Windows, not tested under Linux) it displays the checklist in gray and the scrollbars are also disabled.
« Last Edit: December 10, 2019, 03:28:16 pm by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Disabling a CheckListBox
« Reply #1 on: December 10, 2019, 03:08:10 pm »
These work on Linux:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckListBox1ItemClick(Sender: TObject; Index: integer);
  2. begin
  3.   CheckListBox1.Checked[Index] := not(CheckListBox1.Checked[Index]);
  4. end;

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   for i := 0 to CheckListBox1.Items.Count-1 do
  6.     CheckListBox1.ItemEnabled[i] := False;
  7. end;

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Disabling a CheckListBox
« Reply #2 on: December 10, 2019, 03:27:55 pm »
@Handoko,

Also works fine under Windows.

Thank you very much!

Cheers,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

 

TinyPortal © 2005-2018