Announcement

Collapse
No announcement yet.

Checkbox checking issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checkbox checking issue

    Hello,

    I have the following situation:
    - a Check Boxes screen in the setup
    - 2 checkboxes: Checkbox03 and Checkbox04
    Click image for larger version

Name:	checkboxes.JPG
Views:	29
Size:	2.2 KB
ID:	305745




    - action: when Checkbox03 is check, I want Checkbox04 to be automatically selected as well. For this I have the following code:

    props = DlgCheckBox.GetProperties(CTRL_CHECK_BOX_03);
    if (props.Checked == true) then
    DlgCheckBox.SetProperties(CTRL_CHECK_BOX_04, {Checked=true});
    end

    - Checkbox04 can be selected independently of CheckBox03, but when Checkbox03 is checked, it must also check Checkbox04

    Issue:
    - when both checkboxes are selected, and I click on the Checkbox04, the checkbox will remain visually checked, as it should, but it will actually become unchecked in the background and cause issues during the installation phase.

    How can I make Checkbox04 become permanently checked and not uncheck itself in the background, when both checkboxes are checked?


    Thank you,
    Cosmin

  • #2
    If the fourth checkbox is to be checked automatically when the third is selected, and you cannot allow it to be manually unchecked, then you should probably disable it to prevent the user from making further changes. Also, when the option becomes enabled again, it should restore the previous state properly, which may have been checked or unchecked. Check this out:



    Here is the code to make this work, place it into the On Ctrl Message event script:

    Code:
    if (e_CtrlID == CTRL_CHECK_BOX_03) then
       -- checkbox was clicked
       local tProps = DlgCheckBox.GetProperties(CTRL_CHECK_BOX_03);
       if tProps.Checked then
           -- save previous state
          bC4WasChecked = DlgCheckBox.GetProperties(CTRL_CHECK_BOX_04).Checked;
          -- checkbox was checked, lock child
          DlgCheckBox.SetProperties(CTRL_CHECK_BOX_04, { Checked=true, Enabled=false });
       else
          -- checkbox was unchecked, unlock child and return state
          DlgCheckBox.SetProperties(CTRL_CHECK_BOX_04, { Checked = bC4WasChecked, Enabled=true });
       end
    end
    And this goes into the On Next script, just for testing purposes, if you want (you find this example in the help file):

    Code:
    -- Create a string to hold the checkbox states that were checked to be displayed in the dialog box.
    strTheseChecked = "The following checkboxes were checked:\r\n";
    
    -- Check if the first checkbox was checked.
    if (check01) then
        -- Get the properties of the first checkbox.
       tbCheck1 = DlgCheckBox.GetProperties(CTRL_CHECK_BOX_01);
    
       -- Add the variable name of the checkbox and its label it to the dialog string.
       strTheseChecked = String.Concat(strTheseChecked, tbCheck1.Text.." - check01\r\n");
    end
    
    -- Check if the second checkbox was checked.
    if (check02) then
       -- Get the properties of the second checkbox.
       tbCheck2 = DlgCheckBox.GetProperties(CTRL_CHECK_BOX_02);
    
       --- Add the variable name of the checkbox and its label it to the dialog string.
       strTheseChecked = String.Concat(strTheseChecked, tbCheck2.Text.." - check02\r\n");
    end
    
    -- Check if the third checkbox was checked.
    if (check03) then
       -- Get the properties of the third checkbox.
       tbCheck3 = DlgCheckBox.GetProperties(CTRL_CHECK_BOX_03);
    
       --- Add the variable name of the checkbox and its label it to the dialog string.
       strTheseChecked = String.Concat(strTheseChecked, tbCheck3.Text.." - check03\r\n");
    end
    
    -- Check if the fourth checkbox was checked.
    if (check04) then
       -- Get the properties of the fourth checkbox.
       tbCheck4 = DlgCheckBox.GetProperties(CTRL_CHECK_BOX_04);
    
       --- Add the variable name of the checkbox and its label it to the dialog string.
       strTheseChecked = String.Concat(strTheseChecked, tbCheck4.Text.." - check04\r\n");
    end
    
    -- Display a dialog containing the states of each checkbox.
    -- Check if at least one of the checkboxes are checked.
    if (check01 or check02 or check03 or check04) then
       Dialog.Message("Checkboxes", strTheseChecked, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    else
       -- No checkboxes were checked.
       Dialog.Message("Checkboxes", "No checkboxes were checked.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    end
    Click image for larger version

Name:	SCRN-2020-11-16-01.png
Views:	36
Size:	36.7 KB
ID:	305750

    Ulrich

    Comment


    • #3
      Thank you, Ulrich!

      Your solutions are great, as always. I didn't think to disable the Checkbox04 to lock it's state, I'll keep that in mind.

      Comment

      Working...
      X