Recent

Author Topic: [solved] which checkbox was clicked in TCheckListBox ?  (Read 1607 times)

dbannon

  • Hero Member
  • *****
  • Posts: 756
    • tomboy-ng, a rewrite of the classic Tomboy
[solved] which checkbox was clicked in TCheckListBox ?
« on: January 29, 2018, 01:39:32 pm »
I'm using a TCheckListBox and want to know which one the user has just clicked. On Win/Linux clicking a checkbox also selects that item so you can look at ItemIndex when CheckListBox1ClickCheck fires. But on the Mac the selected item does not change when a checkbox is clicked.

I'm not sure if I should rely on that connection anyway, its certainly not documented anywhere that clicking a checkbox should select that item.

I can keep a separate list of which ones are ticked and then scan over the listbox and see which one has changed but that does seem messy !

Does anyone else know of any way to get an index to a clicked checkbox on TCheckListBox ?

Davo 
« Last Edit: January 30, 2018, 03:56:03 am by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

howardpc

  • Hero Member
  • *****
  • Posts: 3183
Re: which checkbox was clicked in TCheckListBox ?
« Reply #1 on: January 29, 2018, 02:15:55 pm »
Code: Pascal  [Select]
  1. procedure TForm1.CheckListBox1ItemClick(Sender: TObject; Index: integer);
  2. begin
  3.   WriteLn('Index of clicked checkbox is ',Index,', Checked state is ',(Sender as TCheckListBox).Checked[Index]);
  4. end;

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Re: which checkbox was clicked in TCheckListBox ?
« Reply #2 on: January 29, 2018, 02:18:36 pm »
Yes, OnItemClick is the way + you can fill bugreport (if it is not already reported).
Lazarus 2.1.0 r61214:62238 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

dbannon

  • Hero Member
  • *****
  • Posts: 756
    • tomboy-ng, a rewrite of the classic Tomboy
Re: which checkbox was clicked in TCheckListBox ?
« Reply #3 on: January 30, 2018, 03:55:33 am »
Yep, thanks, thats definitly the solution. I just needed to search a bit harder !

I'll put something on the TCheckListBox wiki page, sadly its almost blank.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng