Combobox, textbox and hashtable

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Toroyvaca
Posts: 3
Last visit: Sun Sep 17, 2017 7:09 am

Combobox, textbox and hashtable

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Combobox, textbox and hashtable

Post by jvierra »

Very simple:

$combobox.Items.AddRange($hashtable.Keys)
User avatar
Toroyvaca
Posts: 3
Last visit: Sun Sep 17, 2017 7:09 am

Re: Combobox, textbox and hashtable

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Combobox, textbox and hashtable

Post by jvierra »

Simple:

$textbox_test.Text= $Fichier_Config_INI.Section1[$this.SelectedItem]
User avatar
Toroyvaca
Posts: 3
Last visit: Sun Sep 17, 2017 7:09 am

Re: Combobox, textbox and hashtable

Post by Toroyvaca »

Thanks you very much. It works perfect!
This topic is 6 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked