Page 1 of 1

Combobox, textbox and hashtable

Posted: Wed Sep 13, 2017 3:24 pm
by Toroyvaca
Hello,

I'm new in powershell :roll:

I've got a hashtable (let's say HashTable1) built from an ini file:

[Section1]
a="1.1"
b="2.1"
c="2.6"

In the console, printing $HashTable1.Section1 returns :

Name Value
===== =====
a "1.1"
b "2.1"
c "2.6"

In my GUI, I would like to populate a combobox with the Keys of the hash table (a, b, c)
When the user selects an item in the combobox, the textbox would be filled with the correct value of the hashtable ("1.1", "2.1" or "2.6")

How can I do that ?

#Parsing ini file
$Fichier_Config_INI = Get-IniContent("D:\Config.ini")

I've linked my hash table to the datasource of the combobox :
$combobox_test.DataSource = $Fichier_Config_INI.Section1.Keys | % tostring

And then write the event of the combobox :
$combobox_test_SelectedIndexChanged={
#TODO: Place custom script here
$textbox_test.Text= ?????


Thanks very much for your help
Regards

Re: Combobox, textbox and hashtable

Posted: Wed Sep 13, 2017 3:29 pm
by jvierra
Very simple:

$combobox.Items.AddRange($hashtable.Keys)

Re: Combobox, textbox and hashtable

Posted: Thu Sep 14, 2017 3:51 am
by Toroyvaca
Thanks for your help. I will try this evening.

What about displaying in the textbox the value of the hash table corresponding to thé hashtable Key selected in the combobox ?

Thanks

Re: Combobox, textbox and hashtable

Posted: Thu Sep 14, 2017 9:47 am
by jvierra
Simple:

$textbox_test.Text= $Fichier_Config_INI.Section1[$this.SelectedItem]

Re: Combobox, textbox and hashtable

Posted: Thu Sep 14, 2017 1:06 pm
by Toroyvaca
Thanks you very much. It works perfect!