lundi 14 décembre 2020

Powershell : Button 'select all' and 'unselect all' checkboxes, the 'unselect' one not working. Any idea?

I would like a simple button to select all checkboxes on click, and then change to a 'unselect all' checkboxes and unselect all if clicked.

Actually, everything i tried is not working for the 'UNSELECT' part. However, the SELECT ALL is working properly. Once everything is selected, the button change to 'UNSELECT ALL' but when clicking, it DOES not uncheck the check boxes even thought the instruction is set to 'false'.

How could i fix this issue ?

In the code, i've took off the xml portion to facilitate reading. Scrool down till the '# ///////////// HERE /////////////////////' Thank you !

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 
Add-Type -AssemblyName PresentationCore, PresentationFramework
# Les tab 1 et 2 ont été inversées dans le PWSH, donc il est normal que le nom des variables(Tab1-Tab2) ne corresponde pas avec le chiffre dans le nom de l'objet en XAML. À modifier.


#regions ---- XAML -----
[xml]$xaml = @"
    #... 
"@

#Read XAML (Parse it)
$reader=(New-Object System.Xml.XmlNodeReader $XAML)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
#endregion

#region ----- xaml objects to variables -----


#Connect to Controls TAB1
$Tab1CBB1 = $Window.FindName('CBBdeRep2')
$Tab1CBB2 = $Window.FindName('CBBdeSerie2')
$Tab1CBB3 = $Window.FindName('CBBversRep2')
$Tab1CBB4 = $Window.FindName('CBBversSerie2')
$Tab1CBbin = $Window.FindName('CBbin2')
$Tab1CBexport = $Window.FindName('CBexport2')
$Tab1CBparam = $Window.FindName('CBparam2')
$Tab1CBlist = $Window.FindName('CBlist2')
$Tab1CBscript = $Window.FindName('CBscript2')
$Tab1CBtemplate = $Window.FindName('CBtemplate2')
$Tab1TBmessages = $Window.findName("TBmessages2")
$Tab1BTNsynchro = $Window.findName("BTNsynchro")
$Tab1BTNall = $Window.findName("BTNall1")

#Connect to Controls TAB2
$Tab2CBB1 = $Window.FindName('CBBdeRep1')
$Tab2CBB2 = $Window.FindName('CBBdeSerie1')
$Tab2CBB3 = $Window.FindName('CBBversRep1')
$Tab2TB4 = $Window.FindName('TBversSerie1')
$Tab2CBbin = $Window.FindName('CBbin1')
$Tab2CBexport = $Window.FindName('CBexport1')
$Tab2CBparam = $Window.FindName('CBparam1')
$Tab2CBlist = $Window.FindName('CBlist1')
$Tab2CBscript = $Window.FindName('CBscript1')
$Tab2CBtemplate = $Window.FindName('CBtemplate1')
$Tab2TBmessages = $Window.findName("TBmessages1")
$Tab2BTNcreation = $Window.findName("BTNcreation")
$Tab2BTNall = $Window.findName("BTNall1")
$Tab2CBGroup = $Window.findName("CheckBoxGroup1")


#Connect to Controls TAB2
$Tab3CBBversion = $Window.findName("CBBversion3")
$Tab3TBbuild = $Window.findName("TBbuild3")
$Tab3TBrev = $Window.findName("TBrevision3")
$Tab3CBBequipe = $Window.findName("CBBequipe3")
$Tab3CBBliste = $Window.findName("CBBliste3")
$Tab3CBrtf = $Window.findName("CBrtf3")
$Tab3TBmessages = $Window.findName("TBmessages3")
$Tab3BTNexecution = $Window.findName("BTNexecution")
#endregion

#region ---- Path variables  ----- 
[STRING]$pathDE='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\'
[STRING]$pathVERS='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\VERS\'
[STRING]$pathDBQcust01='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\DBQcust01\Sets\' 
[STRING]$pathQA14='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets\'
[STRING]$pathQA15='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA15\Sets\'
[STRING]$pathSERIE = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets'  #simulation
[STRING]$pathSIMULATION = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation'
[STRING]$pathSPMT = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\VERS\SPMT'
[STRING]$pathOTHER = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\VERS\OTHER'

#endregion ----

#region ---- lists of series ----
$listQA14 = Get-ChildItem $pathQA14 -Directory -Name 
$listQA15 = Get-ChildItem $pathQA15 -Directory -Name 
$listDBQcust01 = Get-ChildItem $pathDBQcust01 -Directory -Name 
$FolderLists = Get-ChildItem $pathSIMULATION\Listes -Include *.txt -Name
$listSPMT = Get-ChildItem $pathSPMT -Directory -Name 
$listOTHER = Get-ChildItem $pathOTHER -Directory -Name 
$listDE = Get-ChildItem $pathDE -Directory -Name 
$listVERS = Get-ChildItem $pathVERS -Directory -Name 
#endregion




#------------- TAB1 ------------------





#region /// ComboBox 1 : DE folder
[ARRAY]$FoldersCBB1 = @($listDE)
$Tab1CBB1.Items.Add('--- choisir ---')
$Tab1CBB1.SelectedItem = '--- choisir ---'
foreach ($Folder in $FoldersCBB1) {
$Tab1CBB1.Items.Add($Folder)
}
#endregion




#region /// ComboBox 2 : DE SERIE    
$Tab1CBB1.add_SelectionChanged({
$Selection = ($Tab1CBB1.SelectedItem.ToString())

  if ($Selection -eq 'QA14') 
    { 
        $Tab1CBB2.Items.Clear()
        $Tab1CBB2.Items.Add('--- choisir une série sous QA14 ---')
        $Tab1CBB2.SelectedItem = '--- choisir une série sous QA14 ---' 
        foreach ($Serie in $listQA14) {
            $Tab1CBB2.Items.Add($Serie)
        }   
    }   
    
    elseif ($Selection -eq 'QA15') 
    {
            $Tab1CBB2.Items.Clear()
            $Tab1CBB2.Items.Add('--- choisir une série sous QA15 ---')
            $Tab1CBB2.SelectedItem = '--- choisir une série sous QA15 ---'
            foreach ($Serie in $listQA15)  {
                $Tab1CBB2.Items.Add($Serie)
            }
    }    
    
    elseif ($Selection -eq 'DBQcust01') 
    {
            $Tab1CBB2.Items.Clear()
            $Tab1CBB2.Items.Add('--- choisir une série sous DBQcust01 ---')
            $Tab1CBB2.SelectedItem = '--- choisir une série sous DBQcust01 ---'
            foreach ($Serie in $listDBQcust01) {
                 $Tab1CBB2.Items.Add($Serie)
            }
   }

    $SelectionCBB2 = ($Tab1CBB2.SelectedValue)
    $SelectionCBB3 = ($Tab1CBB3.SelectedValue)

})

#endregion




#region /// ComboBox 3 : VERS folder
$FoldersCBB3 = @($listVERS)
$Tab1CBB3.Items.Add('--- choisir ---')
$Tab1CBB3.SelectedItem = '--- choisir ---' 
foreach ($Folder in $FoldersCBB3) {
    $Tab1CBB3.Items.Add($Folder)
}

#endregion




#region /// ComboBox 4 : VERS SÉRIE

$Tab1CBB3.add_SelectionChanged({
$Selection = ($Tab1CBB3.SelectedItem.ToString())

  if ($Selection -eq 'SPMT') 
    { 
        $Tab1CBB4.Items.Clear()
        $Tab1CBB4.Items.Add('--- choisir une série sous SPMT ---')
        $Tab1CBB4.SelectedItem = '--- choisir une série sous SPMT ---' 
        foreach ($Serie in $listSPMT) {
            $Tab1CBB4.Items.Add($Serie)
        }   
    }   
    
    elseif ($Selection -eq 'OTHER') 
    {
            $Tab1CBB4.Items.Clear()
            $Tab1CBB4.Items.Add('--- choisir une série sous OTHER ---')
            $Tab1CBB4.SelectedItem = '--- choisir une série sous OTHER ---'
            foreach ($Serie in $listOTHER)  {
                $Tab1CBB4.Items.Add($Serie)
            }
    }    
    
    $SelectionCBB2 = ($Tab1CBB2.SelectedValue)
    $SelectionCBB3 = ($Tab1CBB3.SelectedValue)
    $SelectionCBB4 = ($Tab1CBB4.SelectedValue)
})
#endregion


#$Tab1GroupCB = "$Tab1CBbin,$Tab1CBexport,$Tab1CBscript,$Tab1CBparam,$Tab1CBtemplate,$Tab1CBlist"

///////////// HERE /////////////////////

$Tab1BTNall.Add_Click({

    If ($Tab1BTNall.Content = "SELECT ALL") 
    {
        $Tab1CBbin.IsChecked = "True"
        $Tab1CBparam.IsChecked = "True"
        $Tab1CBtemplate.IsChecked = "True"
        $Tab1CBscript.IsChecked = "True"
        $Tab1CBexport.IsChecked = "True"
        $Tab1CBlist.IsChecked = "True"
        $Tab1BTNall.Content = "UNSELECT ALL"
    }

    ElseIf ($Tab1BTNall.Content = "UNSELECT ALL") 
    {
        $Tab1CBbin.IsChecked = "False"
        $Tab1CBparam.IsChecked = "False"
        $Tab1CBtemplate.IsChecked = "False"
        $Tab1CBscript.IsChecked  = "False"
        $Tab1CBexport.IsChecked  = "False"
        $Tab1CBlist.IsChecked  = "False"
        $Tab1BTNall.Content = "SELECT ALL"
    }
    Else
    {}
})




#Displays the Window
$Window.ShowDialog() | out-null



Aucun commentaire:

Enregistrer un commentaire