The original code - which was really just to show what could be done - assumed that the setting of the '3rd' state would be done programmatically, and that the end-user would/should simply only be able to set the checkbox to True or False. However, there are some circumstances where you may indeed wish to allow the end user to cycle through all the three states.
Hans van de Laar kindly came up with the following and gave permission for me to post his solution on here. So, thank you Hans
Code:
Function NotifyItemChecked Returns Boolean
Boolean bCancel bTristate bAllowFullCycle
Integer iValue
String sOldValue sValue
Get pbTristateCheckbox to bTristate
Get pbTristateAllowFullCycle to bAllowFullCycle
If (bTristate and bAllowFullCycle) Begin
Get SelectedRowValueBeforeEdit to sOldValue
Get ValueToTristate sOldValue to iValue
Increment iValue
If (iValue > 2) Begin
Move 0 to iValue
End
Get TristateToValue iValue to sValue
Send UpdateCurrentValue sValue
Send OnEndEdit sOldValue sValue
End
Else Begin
Forward Get NotifyItemChecked to bCancel
End
Function_Return bCancel
End_Function
The above should be added to the Column Class, along with the following property:
Code:
{Category=Behavior}
Property Boolean pbTristateAllowFullCycle False
This simply allows you to control whether or not you want to allow cycling through all 3 states on a column by column basis (sometimes you might want to, others not)
Hans also kindly pointed out a slight bug in the original code too:
Code:
{MethodType=Property InitialValue=False}
{Category=Appearance }
Procedure Set pbTristateCheckbox Boolean bValue
Set pbCheckbox to True
Set Private_pbTristateCheckbox to True
End_Procedure
This should of course be:
Code:
{MethodType=Property InitialValue=False}
{Category=Appearance }
Procedure Set pbTristateCheckbox Boolean bValue
Set pbCheckbox to bValue
Set Private_pbTristateCheckbox to bValue
End_Procedure
(although as "false" was the default, you'd probably not add the code unless you were setting it to True, so I nearly got away with it! That said, if you the column to be a Checkbox column but you're still adding the code "Set pbTristateCheckbox to False", remember to set pbCheckbox to True again afterwards.)
Thanks Hans.