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 4 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

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

Post by mmmoi5 »

This is what I like about your efforts, you never give up on us seeking to learn, and for that thank you.

But yes I am aware of the fact that they are numbered progressively as one adds objects from the toolbox.
But I believe the system is struggeling with the fact that combobox1 has no property named "SelectedIndexChanged" (which comes after the "." trailing after combobox1 in Your method example)
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 »

It was an example and not I ntended to be just copied into you form.

Take this code and add it to you "SelectedIndexChanged event.


$items = if($this.Text -eq 'ListOfLetters){@('A','B','C')}else{){@('1','2','3')}
$comboBox2.Items.Clear()
$comboBox2.Items.AddRange($items)
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 am familiar with the formulation of this content (corrected for what I believe was a typo on your behalf)

Code: Select all

$items = if ($this.Text -eq 'ListOfLetters'){@('A','B','C')}else{@('1','2','3')}
$comboBox2.Items.Clear()
$comboBox2.Items.AddRange($items)
The problem resides in the fact that the event is not working, and combobox2 is not presenting content at all,

Your idea Works, thanks for the help, it turned out to be the typo that stopped it from working.
combobox1_SelectedIndexChanged instead of combobox1.SelectedIndexChanged (underscore instead of a period)
and the closing apostrophee after listofletters along with an extra closing paranthesis.

Many thanks for a rich learning experience once again.
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 »

Without all of your code I have no idea what you are trying to do.
Look at the full example that I posted much earlier.
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 agree, but you were not very far off and your proposed solution was the correct one.
I did view the example, that did help.
Thanks
This topic is 6 years and 4 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