none
Récuperer valeur combobox RRS feed

  • Question

  • Salut !

    #Generated Form Function
    import-module activedirectory
    function GenerateForm {
    ########################################################################
    # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
    # Generated On: 05/09/2015 13:48
    # Generated By: 
    ########################################################################
    
    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    #endregion
    
    #region Generated Form Objects
    $form1 = New-Object System.Windows.Forms.Form
    $Label_ville = New-Object System.Windows.Forms.Label
    $comboBox2_ville = New-Object System.Windows.Forms.ComboBox
    $comboBox1_BU = New-Object System.Windows.Forms.ComboBox
    $Label_BU = New-Object System.Windows.Forms.Label
    $textBox_prenom = New-Object System.Windows.Forms.TextBox
    $Label_Prenom = New-Object System.Windows.Forms.Label
    $textBox_name = New-Object System.Windows.Forms.TextBox
    $Label_Nom = New-Object System.Windows.Forms.Label
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    #endregion Generated Form Objects
    
    #----------------------------------------------
    #Generated Event Script Blocks
    #----------------------------------------------
    #Provide Custom Code for events specified in PrimalForms.
    $Combobox1_BU_SelectedIndexChanged={
    Load-ComboBox $Combobox2_Ville (Get-ADOrganizationalUnit -searchbase "OU=$UO,DC=CONTOSO,DC=FR" -Searchscope 1 -Filter * ) -DisplayMember "Name"
    }
    $handler_label4_Click= 
    {
    #TODO: Place custom script here
    
    }
    
    $handler_label2_Click= 
    {
    #TODO: Place custom script here
    
    }
    
    $handler_comboBox1_SelectedIndexChanged= 
    {
    #TODO: Place custom script here
    
    }
    
    $handler_label1_Click= 
    {
    #TODO: Place custom script here
    
    }
    
    $handler_form1_Load= 
    {
    #TODO: Place custom script here
    
    }
    
    $OnLoadForm_StateCorrection=
    {#Correct the initial state of the form to prevent the .Net maximized form issue
    	$form1.WindowState = $InitialFormWindowState
    }
    
    #----------------------------------------------
    #region Generated Form Code
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 207
    $System_Drawing_Size.Width = 387
    $form1.ClientSize = $System_Drawing_Size
    $form1.DataBindings.DefaultDataSourceUpdateMode = 0
    $form1.Name = "form1"
    $form1.Text = "Primal Form"
    $form1.add_Load($handler_form1_Load)
    function Load-ComboBox 
    {
        Param (
            [Parameter(Mandatory=$true)]
            [System.Windows.Forms.ComboBox]$ComboBox,
            [Parameter(Mandatory=$true)]
            $Items,
            [Parameter(Mandatory=$false)]
            [string]$DisplayMember,
            [switch]$Append
        )
        
        if(-not $Append)
        {
            $comboBox.Items.Clear()    
        }
        
        if($Items -is [Array])
        {
            $comboBox.Items.AddRange($Items)
        }
        else
        {
            $comboBox.Items.Add($Items)    
        }
    
        $comboBox.DisplayMember = $DisplayMember    
    }
    
    $Label_ville.DataBindings.DefaultDataSourceUpdateMode = 0
    
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 12
    $System_Drawing_Point.Y = 109
    $Label_ville.Location = $System_Drawing_Point
    $Label_ville.Name = "Label_ville"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 55
    $Label_ville.Size = $System_Drawing_Size
    $Label_ville.TabIndex = 7
    $Label_ville.Text = "Ville"
    $Label_ville.add_Click($handler_label4_Click)
    
    $form1.Controls.Add($Label_ville)
    
    $comboBox2_ville.DataBindings.DefaultDataSourceUpdateMode = 0
    $comboBox2_ville.DropDownStyle = 2
    $comboBox2_ville.FormattingEnabled = $True
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 73
    $System_Drawing_Point.Y = 109
    $comboBox2_ville.Location = $System_Drawing_Point
    $comboBox2_ville.Name = "comboBox2_ville"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 21
    $System_Drawing_Size.Width = 134
    $comboBox2_ville.Size = $System_Drawing_Size
    $comboBox2_ville.TabIndex = 6
    Load-ComboBox $Combobox2_Ville (Get-ADOrganizationalUnit -searchbase "OU=$UO,DC=CONTOSO,DC=FR" -Searchscope 1 -Filter * ) -DisplayMember "Name"
    $comboBox1_BU.add_SelectedIndexChanged($comboBox1_BU_SelectedIndexChanged)
    
    $form1.Controls.Add($comboBox2_ville)
    
    $comboBox1_BU.DataBindings.DefaultDataSourceUpdateMode = 0
    $comboBox1_BU.DropDownStyle = 2
    $comboBox1_BU.FormattingEnabled = $True
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 73
    $System_Drawing_Point.Y = 80
    $comboBox1_BU.Location = $System_Drawing_Point
    $comboBox1_BU.Name = "comboBox1_BU"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 21
    $System_Drawing_Size.Width = 134
    $comboBox1_BU.Size = $System_Drawing_Size
    $comboBox1_BU.TabIndex = 5
    Load-ComboBox $Combobox1_BU (Get-ADOrganizationalUnit -Searchscope 1 -Filter * ) -DisplayMember "Name"
    $Combobox1_BU.SelectedItem = $comboBox1_BU.Items[0]
    $UO = $Combobox1_BU.SelectedItem
    
    $form1.Controls.Add($comboBox1_BU)
    
    $Label_BU.DataBindings.DefaultDataSourceUpdateMode = 0
    
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 13
    $System_Drawing_Point.Y = 83
    $Label_BU.Location = $System_Drawing_Point
    $Label_BU.Name = "Label_BU"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 64
    $Label_BU.Size = $System_Drawing_Size
    $Label_BU.TabIndex = 4
    $Label_BU.Text = "BU "
    
    $form1.Controls.Add($Label_BU)
    
    $textBox_prenom.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 73
    $System_Drawing_Point.Y = 53
    $textBox_prenom.Location = $System_Drawing_Point
    $textBox_prenom.Name = "textBox_prenom"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 20
    $System_Drawing_Size.Width = 134
    $textBox_prenom.Size = $System_Drawing_Size
    $textBox_prenom.TabIndex = 3
    
    $form1.Controls.Add($textBox_prenom)
    
    $Label_Prenom.DataBindings.DefaultDataSourceUpdateMode = 0
    
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 13
    $System_Drawing_Point.Y = 60
    $Label_Prenom.Location = $System_Drawing_Point
    $Label_Prenom.Name = "Label_Prenom"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 64
    $Label_Prenom.Size = $System_Drawing_Size
    $Label_Prenom.TabIndex = 2
    $Label_Prenom.Text = "Prenom "
    $Label_Prenom.add_Click($handler_label2_Click)
    
    $form1.Controls.Add($Label_Prenom)
    
    $textBox_name.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 73
    $System_Drawing_Point.Y = 24
    $textBox_name.Location = $System_Drawing_Point
    $textBox_name.Name = "textBox_name"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 20
    $System_Drawing_Size.Width = 134
    $textBox_name.Size = $System_Drawing_Size
    $textBox_name.TabIndex = 1
    
    $form1.Controls.Add($textBox_name)
    
    $Label_Nom.DataBindings.DefaultDataSourceUpdateMode = 0
    
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 13
    $System_Drawing_Point.Y = 27
    $Label_Nom.Location = $System_Drawing_Point
    $Label_Nom.Name = "Label_Nom"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 82
    $Label_Nom.Size = $System_Drawing_Size
    $Label_Nom.TabIndex = 0
    $Label_Nom.Text = "Nom"
    $Label_Nom.add_Click($handler_label1_Click)
    
    $form1.Controls.Add($Label_Nom)
    
    #endregion Generated Form Code
    
    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($OnLoadForm_StateCorrection)
    #Show the Form
    $form1.ShowDialog()| Out-Null
    
    } #End Function
    
    #Call the Function
    GenerateForm
    

    En résumé :

    La combobox1 récupère mes OU de premier niveau

    La deuxième est censé me récupérer les OU qu'il y a a l'interieur de la première

    Problème : Je ne sais pas comment on récupère l'OU sélectionné dans la premiere combobox

    Quand j'essaye :

    Pour recuperer la valeur de la 1ère combobox :
    $UO = $Combobox1_BU.SelectedItem
    ---
    Load-ComboBox $Combobox2_Ville (Get-ADOrganizationalUnit -searchbase "OU=$UO,DC=CONTOSO,DC=FR" -Searchscope 1 -Filter * ) -DisplayMember "Name"
    J'ai une erreur

    La syntaxe de l'objet est incorrecte

    Merci pour votre aide

    samedi 5 septembre 2015 21:52