IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Réutilisez un choix de la ComboBox [PowerShell]


Sujet :

Scripts/Batch

  1. #1
    Membre à l'essai
    Homme Profil pro
    Autres
    Inscrit en
    Janvier 2016
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Autres

    Informations forums :
    Inscription : Janvier 2016
    Messages : 16
    Points : 13
    Points
    13
    Par défaut Réutilisez un choix de la ComboBox
    Bonjour,
    Je sais pas si l'intitulé est clair mais bon, je me lance.

    Je suis actuellement sur un petit développement qui permettra d'installer une imprimante depuis une liste d'imprimantes situé dans un fichier .csv listés dans une combobox.
    Et le soucis que je rencontre est que une fois le choix effectué dans la combobox, je n'arrive pas à le transcrire sur l'action "Installer l'imprimante" avec le nom choisi.

    Dans le code il y a tout le blabla de générations de formes crées par "Primal Form CE".
    Vu que j'ai testé à peu prés tout ($combobox.selected etc...) donc j'ai tout enlevé et gardé que l'essentielle.

    Please Help

    Voici le code :

    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    #Generated Form Function
    function GenerateForm {
     
    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    #endregion
     
    #region Generated Form Objects
    $form1 = New-Object System.Windows.Forms.Form
    $button1 = New-Object System.Windows.Forms.Button
    $comboBox1 = New-Object System.Windows.Forms.ComboBox
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    #endregion Generated Form Objects
     
    #----------------------------------------------
    #Generated Event Script Blocks
    #----------------------------------------------
    #Provide Custom Code for events specified in PrimalForms.
    $button1_OnClick= 
    {
    (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\ServerName\$printtoinstall")
    [System.Windows.Forms.MessageBox]::Show("$printtoinstall",'Résultat','OK','64')
     
    }
     
    $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 = 262
    $System_Drawing_Size.Width = 284
    $form1.ClientSize = $System_Drawing_Size
    $form1.DataBindings.DefaultDataSourceUpdateMode = 0
    $form1.Name = "form1"
    $form1.Text = "Primal Form"
     
     
    $button1.DataBindings.DefaultDataSourceUpdateMode = 0
     
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 146
    $System_Drawing_Point.Y = 189
    $button1.Location = $System_Drawing_Point
    $button1.Name = "button1"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 23
    $System_Drawing_Size.Width = 75
    $button1.Size = $System_Drawing_Size
    $button1.TabIndex = 1
    $button1.Text = "button1"
    $button1.UseVisualStyleBackColor = $True
    $button1.add_Click($button1_OnClick)
     
    $form1.Controls.Add($button1)
     
    $comboBox1.DataBindings.DefaultDataSourceUpdateMode = 0
    $comboBox1.FormattingEnabled = $True
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 46
    $System_Drawing_Point.Y = 46
    $comboBox1.Location = $System_Drawing_Point
    $printlist = Import-Csv .\test.csv  -Delimiter ";" | Select-Object -ExpandProperty Name
    foreach ($printer in $printlist)
    {
    $comboBox1.Items.Add($printer)
    }
    $comboBox1.Name = "comboBox1"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 21
    $System_Drawing_Size.Width = 121
    $comboBox1.Size = $System_Drawing_Size
    $comboBox1.TabIndex = 0
     
     
    $form1.Controls.Add($comboBox1)
     
    #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

  2. #2
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Salut,
    tu as peut être un problème de portée dans les gestionnaires d'événements. Ajoute $script au nom de variable référencée :
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    $button1_OnClick= 
    {
       (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\ServerName\$script:printtoinstall")
       [System.Windows.Forms.MessageBox]::Show("$script:printgo",'Résultat','OK','64')
    }

  3. #3
    Membre à l'essai
    Homme Profil pro
    Autres
    Inscrit en
    Janvier 2016
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Autres

    Informations forums :
    Inscription : Janvier 2016
    Messages : 16
    Points : 13
    Points
    13
    Par défaut
    Merci de la réponse rapide mais à quel moment je lui dit à quoi correspond $printtoinstall et comment?

  4. #4
    Membre à l'essai
    Homme Profil pro
    Autres
    Inscrit en
    Janvier 2016
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Autres

    Informations forums :
    Inscription : Janvier 2016
    Messages : 16
    Points : 13
    Points
    13
    Par défaut Nouveauté
    En ajoutant le selectedindex ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $printtoinstall = $combobox1.selectedindex
    (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\ServerName\$printtoinstall")
    [System.Windows.Forms.MessageBox]::Show("$printtoinstall",'Résultat','OK','64')
    Il me trouve le numero d'index correspondant au choix de la combobox.
    Comment la " retraduire"?

  5. #5
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par Basss974 Voir le message
    à quel moment je lui dit à quoi correspond $printtoinstall et comment?
    J'ai exécuté ton script, j'ai eu des erreurs je ne suis pas aller plus loin.
    Je pensais que ta variable était déjà définie...

    Citation Envoyé par Basss974 Voir le message
    En ajoutant le selectedindex ici :
    Par exemple.
    Dans ce cas tu es dans la même portée , l'ajout de $script: n'est plus nécessaire.

    Citation Envoyé par Basss974 Voir le message
    Comment la " retraduire"?
    Il ne faut pas hésiter à lire la documentation des composants utilisés.
    Par exemple la propriété Text est à tester.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. passer un choix d'un combobox comme parametre à une requette
    Par roura dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 22/12/2008, 20h47
  2. recupere variables associées au choix d'un combobox
    Par oscar.cesar dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 03/08/2007, 20h34
  3. [C#] Contrôler les choix dans un ComboBox
    Par kinou dans le forum Windows Forms
    Réponses: 1
    Dernier message: 17/08/2006, 14h40
  4. Affichage des infos après le choix d'une combobox
    Par manplum dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 07/08/2006, 10h31
  5. choix dans un combobox
    Par awax dans le forum Delphi
    Réponses: 3
    Dernier message: 01/06/2006, 13h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo