Does anyone have a working example of selectedindexchanged (combobox)

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 5 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
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

Does anyone have a working example of selectedindexchanged (combobox)

Post by mmmoi5 »

I need the Form GUI to automatically load one of two lists into combobox2 when a Choice is made in combobox1.
I have read about selectedindexchanged but I cannot seem to automate that without a refresh button.

Anyone have a working example of how to achieve this.

Thanks
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by jvierra »

If you search this forum you will find numerous examples of this.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by jvierra »

User avatar
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by mmmoi5 »

Thank you, I came across that one before not exactly what I was looking for or maybe I am missing something, but thanks for the headsup.
My combobox1 is "ListOfNumbers","ListOfLetters"
My combobox2 is either list "1","2","3" or "A","B","C".
When user chooses ListOfNumbers from dropdown a list of Choices "1,2,3" show up in combox2.
and when ListOfLetters is chosen, the dropdown lists Choices "A,B,C"
I have gotten that to work with an refresh button and an if statement. But I cannot seem to figure out how to update automatically.
That is where my knowledge comes up short.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by jvierra »

What does "update automatically" mean?

The "SelectedIndexChanged" event is where you would reset the second ComboBox items.

Code: Select all

$comboBox1SelectedIndexChanged = {
       $items =   if($this.Text -eq 'ListOfLetters){@('A','B','C')}else{){@('1','2','3')}
      $comboBox2.Items.Clear()
      $comboBox2.Items.AddRange($items)
  
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by jvierra »

Here is a full working example of how to synchronize lists.
Attachments
FunWithLists.psf
(27.8 KiB) Downloaded 227 times
User avatar
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by mmmoi5 »

I attempted the proposed code and I get
ERROR: The property 'SelectedIndexChanged' cannot be found on this object. (which is reasonable since it does not exist)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by jvierra »

What proposed code. I posted an example. You need to change your code to use the method in the example.
User avatar
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by mmmoi5 »

I did used the proposed Method and adapted it to my needs (that is what I meant with code).
The proposed method starts off with "comboBox1.SelectedIndexChanged" which is a none existing property.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Does anyone have a working example of selectedindexchanged (combobox)

Post by jvierra »

$ComboBox

You must use the variable whatever you named it. By default PSS names the first ComboBox variable $combobox1 and increments the number for each box. You have to use the variable that was created. It may be 1,2,3 or other depending on the number and order of the boxes you added in the designer.

To learn about how to use this control go here: https://info.sapien.com/index.php/guis/ ... ox-control
This topic is 6 years and 5 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