locked
make one checkbox disabled while another one is checked RRS feed

  • Question

  • Hello,

    I woud like to make one checkbox disabled if another one is checked and vice versa.

    I do something like that:

    $pageFileCheckbox = New-Object System.Windows.Forms.Checkbox 
    $pageFileCheckbox.Location = New-Object System.Drawing.Size(10,390)
    $pageFileCheckbox.Size = New-Object System.Drawing.Size(150,20)
    $pageFileCheckbox.Text = "Default value = 1,5*RAM"
    
    $pageFileCheckboxNotDefault = New-Object System.Windows.Forms.Checkbox 
    $pageFileCheckboxNotDefault.Location = New-Object System.Drawing.Size(10,410)
    $pageFileCheckboxNotDefault.Size = New-Object System.Drawing.Size(150,20)
    $pageFileCheckboxNotDefault.Text = "Particular value in GB"
    
    if($pageFileCheckbox.checked)
    {
        $pageFileCheckboxNotDefault.Enabled = $false
    }
    This doesnt work of course. I'd like this happen right in the form when user fills up the form. How to achieve that?
    Monday, June 24, 2019 11:56 AM

All replies

  • Use radio buttons are they are exclusive.  When one is set the other is unset automatically.  That is what radio buttons are for.


    \_(ツ)_/

    Monday, June 24, 2019 1:09 PM
  • Thanks but I need particular value to be used when point other than default is chosen. That's not the radio button I need because they don't provide such functionality. So I need checkbox and textbox concurrently.

    Tuesday, June 25, 2019 5:11 AM
  • No.  That is exactly what a radio button does.  It can be set to a default and then selecting a second button changes the value of the radio buttons.


    \_(ツ)_/

    Tuesday, June 25, 2019 5:15 AM
  • by the way sorted out by myself

    $pageFileCheckbox.Add_Click({
        if($pageFileCheckbox.Checked){
            $pageFileCheckboxNotDefault.Enabled = $false
            $pageFileTextBox.Enabled = $false
        }
        elseif($pageFileCheckbox.Checked -eq $false){
            $pageFileCheckboxNotDefault.Enabled = $true
            $pageFileTextBox.Enabled = $true
        }
        }
    )
    
    $pageFileCheckboxNotDefault.Add_Click({
        if($pageFileCheckboxNotDefault.Checked)
        {
            $pageFileCheckbox.Enabled = $false
        }
        elseif($pageFileCheckboxNotDefault.Checked -eq $false)
        {
            $pageFileCheckbox.Enabled = $true
        }
        }
    )

    Tuesday, June 25, 2019 9:10 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, July 9, 2019 7:54 AM