Discussion:
Read-only TCheckListBox
(too old to reply)
Jason Cipriani
2008-06-24 10:31:05 UTC
Permalink
How do I make a TCheckListBox read-only, so the user can't change the check
states?

Thanks,
Jason
yannis
2008-06-24 10:55:59 UTC
Permalink
Post by Jason Cipriani
How do I make a TCheckListBox read-only, so the user can't change the
check states?
Thanks,
Jason
How about enabled := false?

Regards
Yannis.
--
Jason Cipriani
2008-06-24 20:58:12 UTC
Permalink
Post by yannis
Post by Jason Cipriani
How do I make a TCheckListBox read-only, so the user can't change the
check states?
How about enabled := false?
Thanks for your reply. Setting Enabled to false doesn't do what I want, it
grays out the checkboxes (and hides their state) and grays out the text as
well. It also disables the scrollbars. I should have been more specific: I
want the user to still be able to interact with it and browse through the
items -- I just don't want them to be able to change the text. There doesn't
seem to be a ReadOnly property.

Thanks,
Jason
Remy Lebeau (TeamB)
2008-06-24 21:25:13 UTC
Permalink
Post by Jason Cipriani
How do I make a TCheckListBox read-only, so the user can't change the
check states?
TCheckListBox does not natively support that. What you can do, however, is
use the OnClickCheck event to manually reset an item's check state back to
its previous state when clicked, ie:

void __fastcall TForm1::CheckListBox1ClickCheck(TObject *Sender)
{
int idx = CheckListBox1->ItemIndex;
if( idx > -1 )
CheckListBox1->Checked[idx] = !CheckListBox1->Checked[idx];
}



Gambit
Jason Cipriani
2008-06-25 04:54:21 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by Jason Cipriani
How do I make a TCheckListBox read-only, so the user can't change the
check states?
TCheckListBox does not natively support that. What you can do, however,
is use the OnClickCheck event to manually reset an item's check state back
void __fastcall TForm1::CheckListBox1ClickCheck(TObject *Sender)
{
int idx = CheckListBox1->ItemIndex;
if( idx > -1 )
CheckListBox1->Checked[idx] = !CheckListBox1->Checked[idx];
}
That's almost the solution I settled on; although it unfortunately interacts
badly with this issue:

http://qc.codegear.com/wc/qcmain.aspx?d=59271

So in the end my solution for a "read-only" TCheckListBox is to activate a
short TTimer every time you click or double-click it that restores all the
checks to their correct states. Not ideal.

Jason
Remy Lebeau (TeamB)
2008-06-25 06:34:17 UTC
Permalink
Post by Jason Cipriani
So in the end my solution for a "read-only" TCheckListBox is to
activate a short TTimer every time you click or double-click it
that restores all the checks to their correct states.
Alternatively, you can switch to a TListView in vReport mode. Set its
ReadOnly property to true, and use its CheeckBoxes or StateImages property
to display checkbox images. TListItem has Checked and StateIndex
properties.


Gambit
Jason Cipriani
2008-06-25 07:10:59 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by Jason Cipriani
So in the end my solution for a "read-only" TCheckListBox is to
activate a short TTimer every time you click or double-click it
that restores all the checks to their correct states.
Alternatively, you can switch to a TListView in vReport mode. Set its
ReadOnly property to true, and use its CheeckBoxes or StateImages property
to display checkbox images. TListItem has Checked and StateIndex
properties.
Hey, good call!

Thanks for the advice,
Jason

Loading...