Combobox, textbox and hashtable

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Locked
User avatar
Toroyvaca
Posts: 3
Joined: Wed Sep 13, 2017 3:10 pm

Combobox, textbox and hashtable

Post by Toroyvaca » Wed Sep 13, 2017 3:24 pm

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

User avatar
jvierra
Posts: 11489
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Combobox, textbox and hashtable

Post by jvierra » Wed Sep 13, 2017 3:29 pm

Very simple:

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

User avatar
Toroyvaca
Posts: 3
Joined: Wed Sep 13, 2017 3:10 pm

Re: Combobox, textbox and hashtable

Post by Toroyvaca » Thu Sep 14, 2017 3:51 am

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

User avatar
jvierra
Posts: 11489
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Combobox, textbox and hashtable

Post by jvierra » Thu Sep 14, 2017 9:47 am

Simple:

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

User avatar
Toroyvaca
Posts: 3
Joined: Wed Sep 13, 2017 3:10 pm

Re: Combobox, textbox and hashtable

Post by Toroyvaca » Thu Sep 14, 2017 1:06 pm

Thanks you very much. It works perfect!

Locked