Bonjour à tous,
Je suis débutant en powershell et j'apprend sur le tas.
Je travaille actuellement sur un programme qui à besoin d'une connexion sql pour récupérer des donnée et pré remplir certains champs de mon formulaire.
Dans ce programme j'ai créé un combobox auquel je souhaite y attacher une variable pour avoir une liste complète des différentes valeurs.
Cette variable stock de multiples valeurs grâce à une requête sql.
Voici une version simplifié de mon programme :
Ma variable qui stock les différentes valeurs est : $res
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 # sql request [void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data") $ConnStr = “server=xxxxxxx;uid=xxxxxx;password=xxxxxx;database=xxxxxx;Port=xxxxx” $ObjMysql = New-Object MySql.Data.MySqlClient.MySqlConnection($ConnStr) $ObjMysql.Open() $req = "SELECT monchamp FROM matable" $SQLCommand = New-Object MySql.Data.MySqlClient.MySqlCommand($req,$ObjMysql) $MySQLDataAdaptater = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($SQLCommand) $MySQLDataSet = New-Object System.Data.DataSet $RecordCount = $MySQLDataAdaptater.Fill($MySQLDataSet, "Query") $MySQLDataSet.Tables["Query"] $res = $MySQLDataSet.Tables["Query"] $ObjMysql.close() # Create form [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Test" $objForm.Size = New-Object System.Drawing.Size(300,200) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True # add combobox $textWho = New-Object System.Windows.Forms.Combobox $textWho.Location = New-Object System.Drawing.Point(20,75) $textWho.Size = New-Object System.Drawing.Size(140,10) $textWho.DropDownStyle = "DropDownList" $textWho.Items.AddRange = $res $objForm.Controls.Add($textWho) # Add Ok Button $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,120) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $OKButton.Add_Click{ $objForm.Close() } $objForm.Controls.Add($OKButton) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog()
En affichant cette variable j'ai bien toutes mes valeurs, mais je n'arrive pas à la lier à ma dropList.
Ma ligne qui pose problème est :
$textWho.Items.AddRange = $res
J'ai essayé avec des array :
$textWho.Items.AddRange = $res[0], $res[1]....
mais il ne considère pas ma variable comme multiple mais comme une seule et même donnée.
Si quelqu'un pouvais m'éclairer
Merci pour le temps consacré sur mon problème.
PanikPa
Partager