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 :

Combobox modifiée par une autre Combobox


Sujet :

Scripts/Batch

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Février 2015
    Messages : 4
    Points : 1
    Points
    1
    Par défaut Combobox modifiée par une autre Combobox
    Bonjour,

    Je vous présente un peu la chose. J'ai actuellement 3 combobox. La 1ère est fixe (avec X valeurs), la 2ème possède 2 valeurs et la 3ème (le problème) doit afficher des valeurs en fonction de ce qui est sélectionné dans la 2ème.
    Là dans mon cas, pour la 2ème combobox vous avez le choix entre TCP et UDP. Et j'aimerai donc en fonction de ce choix, afficher dans la 3ème combobox certains ports, par exemple 443 et 8080 pour le TCP, et 444 et 8181 pour UDP.

    J'ai fouillé un peu partout sur le net mais pas moyen d'arriver à quelque chose de fonctionnelle. Je n'ai jamais réussi à mettre à jour la 3ème combobox avec le choix de la 2ème.

    Je vous remercie d'avance pour votre aide.

    Cordialement. ptit_poulet

  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,
    Pour ce type de question il est préférable de joindre un code de test.
    Une solution est d'utiliser le DataBinding :
    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
     
    ################################################################################ 
    #
    #  Name    : C:\Temp\BindChkBx\BindChkBx\Form1.ps1  
    #  Version : 0.1
    #  Author  :
    #  Date    : 19/02/2015
    #
    #  Generated with PowerShell V4.0
    #  https://convertform.codeplex.com/
    #
    #  Invocation Line   : Convert-Form C:\Temp\BindChkBx\BindChkBx\Form1.Designer.cs
    #  Source            : C:\Temp\BindChkBx\BindChkBx\Form1.Designer.cs
    ################################################################################
     
    function Get-ScriptDirectory
    { #Return the directory name of this script
      $Invocation = (Get-Variable MyInvocation -Scope 1).Value
      Split-Path $Invocation.MyCommand.Path
    }
     
    $ScriptPath = Get-ScriptDirectory
     
    $TCPports= new-object System.Collections.ArrayList
    443,8080|% { [void]$TCPports.Add((new-Object psobject -Property @{Port=$_.tostring()}))}
     
    $UDPports= new-object System.Collections.ArrayList
    444,8181 |% { [void]$UDPports.Add((new-Object psobject -Property @{Port=$_.tostring()}))}
     
    # Chargement des assemblies externes
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing
     
    $Form1 = New-Object System.Windows.Forms.Form
     
    $cbBoxFixe = New-Object System.Windows.Forms.ComboBox
    $cbBoxProtocols = New-Object System.Windows.Forms.ComboBox
    $cbBoxPorts = New-Object System.Windows.Forms.ComboBox
    #
    # cbBoxFixe
    #
    $cbBoxFixe.FormattingEnabled = $true
    $cbBoxFixe.Items.AddRange(@(
    "Un",
    "Deux",
    "Trois"))
    $cbBoxFixe.Location = New-Object System.Drawing.Point(48, 22)
    $cbBoxFixe.Name = "cbBoxFixe"
    $cbBoxFixe.Size = New-Object System.Drawing.Size(121, 21)
    $cbBoxFixe.TabIndex = 0
    #
    # cbBoxProtocols
    #
    $cbBoxProtocols.FormattingEnabled = $true
    $cbBoxProtocols.Items.AddRange(@(
    "TCP",
    "UDP"))
    $cbBoxProtocols.Location = New-Object System.Drawing.Point(224, 22)
    $cbBoxProtocols.Name = "cbBoxProtocols"
    $cbBoxProtocols.Size = New-Object System.Drawing.Size(121, 21)
    $cbBoxProtocols.TabIndex = 1
     
    $cbBoxProtocols.SelectedIndex = 0
    $cbBoxPorts.DataSource = $TCPports
    $cbBoxPorts.DisplayMember = "Port"
     
    function OnSelectionChangeCommitted_cbBoxProtocols {
      $cbBoxPorts.DataSource = $Null
      if ($this.SelectedItem -eq 'TCP')
      { $cbBoxPorts.DataSource = $TCPports }
      else
      { $cbBoxPorts.DataSource = $UDPports }
      $cbBoxPorts.DisplayMember = "Port"
    }
     
    $cbBoxProtocols.Add_SelectionChangeCommitted( { OnSelectionChangeCommitted_cbBoxProtocols } )
     
    #
    # cbBoxPorts
    #
    $cbBoxPorts.FormattingEnabled = $true
    $cbBoxPorts.Location = New-Object System.Drawing.Point(412, 22)
    $cbBoxPorts.Name = "cbBoxPorts"
    $cbBoxPorts.Size = New-Object System.Drawing.Size(121, 21)
    $cbBoxPorts.TabIndex = 2
    #
    # Form1
    #
    $Form1.ClientSize = New-Object System.Drawing.Size(592, 118)
    $Form1.Controls.Add($cbBoxPorts)
    $Form1.Controls.Add($cbBoxProtocols)
    $Form1.Controls.Add($cbBoxFixe)
    $Form1.Name = "Form1"
    $Form1.Text = "Form1"
     
    function OnFormClosing_Form1{ 
        # $this parameter is equal to the sender (object)
        # $_ is equal to the parameter e (eventarg)
     
        # The CloseReason property indicates a reason for the closure :
        #   if (($_).CloseReason -eq [System.Windows.Forms.CloseReason]::UserClosing)
     
        #Sets the value indicating that the event should be canceled.
        ($_).Cancel= $False
    }
     
    $Form1.Add_FormClosing( { OnFormClosing_Form1} )
     
    $Form1.Add_Shown({$Form1.Activate()})
    $ModalResult=$Form1.ShowDialog()
    # Libération de la Form
    $Form1.Dispose()

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Février 2015
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    @Laurent Dardenne : un grand merci à toi. Je viens de tester rapidement ton script, il fait exactement ce que je recherche. Il me reste plus qu'à décortiquer chaque ligne afin d'en comprendre le fonctionnement. Je débute donc je découvre au fur et à mesure de l'avancée de mon programme. Encore merci

  4. #4
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Février 2015
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Bonsoir,

    J'ai donc réutilisé votre code et j'arrive à faire pile ce que je voulais (j'ai modifié volontairement les ports et autres serveurs pour la mise en ligne du code )


    Code : 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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    ################################################################################ 
    #
    #  Name    : C:\Temp\BindChkBx\BindChkBx\Form1.ps1  
    #  Version : 0.1
    #  Author  :
    #  Date    : 19/02/2015
    #
    #  Generated with PowerShell V4.0
    #  https://convertform.codeplex.com/
    #
    #  Invocation Line   : Convert-Form C:\Temp\BindChkBx\BindChkBx\Form1.Designer.cs
    #  Source            : C:\Temp\BindChkBx\BindChkBx\Form1.Designer.cs
    #
    # Utilisation du DataBinding pour la gestion des combobox dynamique
    #
    ################################################################################
     
    function Get-ScriptDirectory
    { #Return the directory name of this script
      $Invocation = (Get-Variable MyInvocation -Scope 1).Value
      Split-Path $Invocation.MyCommand.Path
    }
     
    $ScriptPath = Get-ScriptDirectory
     
    $TCPports= new-object System.Collections.ArrayList
    1,22,333 |% { [void]$TCPports.Add((new-Object psobject -Property @{Port=$_.tostring()}))}
     
    $UDPports= new-object System.Collections.ArrayList
    4444,55555, |% { [void]$UDPports.Add((new-Object psobject -Property @{Port=$_.tostring()}))}
     
    # Chargement des assemblies externes
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing
     
    $Form1 = New-Object System.Windows.Forms.Form
     
    $cbBoxFixe = New-Object System.Windows.Forms.ComboBox
    $cbBoxProtocols = New-Object System.Windows.Forms.ComboBox
    $cbBoxPorts = New-Object System.Windows.Forms.ComboBox
    #
    # cbBoxFixe
    #
    $cbBoxFixe.FormattingEnabled = $true
    $cbBoxFixe.Items.AddRange(@('srv1','srv2','srv3'))
    $cbBoxFixe.Location = New-Object System.Drawing.Point(22, 22)
    $cbBoxFixe.Name = "cbBoxFixe"
    $cbBoxFixe.Size = New-Object System.Drawing.Size(150, 21)
    $cbBoxFixe.TabIndex = 0
    #
    # cbBoxProtocols
    #
    $cbBoxProtocols.FormattingEnabled = $true
    $cbBoxProtocols.Items.AddRange(@(
    "TCP",
    "UDP"))
    $cbBoxProtocols.Location = New-Object System.Drawing.Point(180, 22)
    $cbBoxProtocols.Name = "cbBoxProtocols"
    $cbBoxProtocols.Size = New-Object System.Drawing.Size(60, 21)
    $cbBoxProtocols.TabIndex = 1
     
    $cbBoxProtocols.SelectedIndex = 0
    $cbBoxPorts.DataSource = $TCPports
    $cbBoxPorts.DisplayMember = "Port"
     
    function OnSelectionChangeCommitted_cbBoxProtocols {
      $cbBoxPorts.DataSource = $Null
      if ($this.SelectedItem -eq 'TCP')
      { $cbBoxPorts.DataSource = $TCPports }
      else
      { $cbBoxPorts.DataSource = $UDPports }
      $cbBoxPorts.DisplayMember = "Port"
    }
     
    $cbBoxProtocols.Add_SelectionChangeCommitted( { OnSelectionChangeCommitted_cbBoxProtocols } )
     
    #
    # cbBoxPorts
    #
    $cbBoxPorts.FormattingEnabled = $true
    $cbBoxPorts.Location = New-Object System.Drawing.Point(250, 22)
    $cbBoxPorts.Name = "cbBoxPorts"
    $cbBoxPorts.Size = New-Object System.Drawing.Size(55, 21)
    $cbBoxPorts.TabIndex = 2
    
    #
    # boxButton
    #
    $Button = New-Object System.Windows.Forms.Button
    $Button.Location = New-Object System.Drawing.Point(55, 60)
    $Button.Size = New-Object System.Drawing.Size(98, 23)
    $Button.Text = "Connexion"
    $Button.add_Click(
    {
        if ($Button.Text -eq "Connexion")
            {
    #       $label.Text = "Connexion sur le serveur :",$cbBoxFixe.SelectedItem.ToString()," avec le protocole :",$cbBoxProtocols.SelectedItem.ToString()," sur le port :", $cbBoxPorts.SelectedItem.ToString()
    #		$label.Text = "Connecté sur :",$cbBoxFixe.SelectedItem.ToString()
    		$label.Text = Get-NetAdapter -Name 'Local Area Connection'|select MediaConnectionState
    		$Button.Text = "Déconnexion"
            $cbBoxFixe.Enabled = $false
            $cbBoxProtocols.Enabled = $false
            $cbBoxPorts.Enabled = $false
    		Start-Process openvpn -WorkingDirectory "C:\Program Files (x86)\OpenVPN\config" -ArgumentList "--config xxxxxxx.ovpn" -NoNewWindow
            }
    
        else 
            {
    #       $label.Text = "Non connecté"
    		$label.Text = Get-NetAdapter -Name 'Local Area Connection'|select MediaConnectionState
            $Button.Text = "Connexion"
            $cbBoxFixe.Enabled = $true
            $cbBoxProtocols.Enabled = $true
            $cbBoxPorts.Enabled = $true
    		Stop-Process -name openvpn
            }
    }
    )
    $Form1.Controls.Add($Button)
    
    
    #
    # boxTextAffichage
    #
    $label = New-Object System.Windows.Forms.Label
    $label.Location = New-Object System.Drawing.Point(22, 95)
    $label.Size = New-Object System.Drawing.Size(300, 23)
    $label.Text = Get-NetAdapter -Name 'Local Area Connection'|select MediaConnectionState
    
    
    #
    # Form1
    #
    $Form1.ClientSize = New-Object System.Drawing.Size(330, 110)
    $Form1.Controls.Add($cbBoxPorts)
    $Form1.Controls.Add($cbBoxProtocols)
    $Form1.Controls.Add($cbBoxFixe)
    $Form1.Controls.Add($label)
    $Form1.Name = "Form1"
    $Form1.Text = "SERVEUR GUI"
     
    function OnFormClosing_Form1{ 
        # $this parameter is equal to the sender (object)
        # $_ is equal to the parameter e (eventarg)
     
        # The CloseReason property indicates a reason for the closure :
        #   if (($_).CloseReason -eq [System.Windows.Forms.CloseReason]::UserClosing)
     
        #Sets the value indicating that the event should be canceled.
        ($_).Cancel= $False
    }
     
    $Form1.Add_FormClosing( { OnFormClosing_Form1} )
     
    $Form1.Add_Shown({$Form1.Activate()})
    $ModalResult=$Form1.ShowDialog()
    
    # Libération de la Form
    $Form1.Dispose()

    Maintenant j'essaye d'afficher le statut de la carte TAP d'OpenVPN. Pour le moment j'y arrive mais malheureusement je n'arrive à mettre à jour le statut que lorsque j'appuie sur le bouton Connexion/Déconnexion. Je n'ai aucune idée de comment le mettre à jour automatiquement et régulièrement. J'ai cherché à droite à gauche, mais je ne sais pas comment faire tourner une tâche en fond pour surveiller tout ça.

    Je crois que je vais finir par investir dans un livre

    Je vous remercie d'avance

  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 ptit_poulet Voir le message
    Je n'ai aucune idée de comment le mettre à jour automatiquement et régulièrement.
    J'ai cherché à droite à gauche, mais je ne sais pas comment faire tourner une tâche en fond pour surveiller tout ça.
    Si tu veux surveiller la connexion, ton soft étant écrit en C, je crains qu'il ne te faille surveiller la connexion en elle même.
    A vérifier si ton soft propose une API de ce type.

    Une piste en PS
    ou .Net. Voir aussi.
    OS requis :Windows 8 / Windows Server 2012.

    Citation Envoyé par ptit_poulet Voir le message
    Je crois que je vais finir par investir dans un livre
    Pour ce pb, pas certains que tu en trouves qui puisse t'aider.
    Enfin pour ce type de traitement (GUI+Event) je doute que PS soit le plus approprié.

  6. #6
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Février 2015
    Messages : 4
    Points : 1
    Points
    1
    Par défaut
    Citation Envoyé par Laurent Dardenne Voir le message
    Si tu veux surveiller la connexion, ton soft étant écrit en C, je crains qu'il ne te faille surveiller la connexion en elle même.
    A vérifier si ton soft propose une API de ce type.
    Je ne comprends pas votre réponse, mon script est en PowerShell et non en C ?

    Sinon pour les liens donnés j'en avais déjà trouvé mais j'ai trouvé la mise en place super lourde.
    Donc effectivement le PowerShell n'est peut-être pas fait pour... C'est à dire que t'en qu'on lui demande de dérouler un script ça va, mais faire une gui avec des processus en arrière plan c'est peut-être pas la meilleure idée

    Une idée peut-être d'un langage simple pour faire une gui avec les fonctions de surveillance que je veux ?

    Merci d'avance

  7. #7
    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 ptit_poulet Voir le message
    Je ne comprends pas votre réponse, mon script est en PowerShell et non en C ?
    Je parlais d'OpenVPN, il existe peut être un callback pour cette fonctionnalité...
    Citation Envoyé par ptit_poulet Voir le message
    mais faire une gui avec des processus en arrière plan c'est peut-être pas la meilleure idée
    Dans un GUI, la gestion d’événement d'objets qui ne sont pas dérivés de la classe Component n'est peut être pas possible avec PS.
    Et la gestion d'événement de PS qui permet de le faire, est différente de celle d'un GUI
    Citation Envoyé par ptit_poulet Voir le message
    Une idée peut-être d'un langage simple pour faire une gui avec les fonctions de surveillance que je veux ?
    C# me semble un bon candidat.

Discussions similaires

  1. Remplir une comboBox à partir d'une autre combobox
    Par karnass dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 13/03/2013, 15h22
  2. Combobox qui définit une autre combobox
    Par veriecherie dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 06/06/2009, 03h44
  3. Réponses: 4
    Dernier message: 04/05/2009, 12h12
  4. ADO remplir combobox d'aprés une autre combobox
    Par frack dans le forum VBA Access
    Réponses: 14
    Dernier message: 09/02/2008, 02h29
  5. Réponses: 3
    Dernier message: 26/09/2007, 14h34

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