ComboBox and ListBox trigger

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 8 years and 1 month 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
saritM
Posts: 3
Last visit: Mon Feb 15, 2016 5:13 am

ComboBox and ListBox trigger

Post by saritM »

Hello,

I have windows form with combobox and listbox.
I want that once item selected in the combobox, the items in the listbox will change accordingly
tried million of options but nothing is working.
can someone please help?

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

Re: ComboBox and ListBox trigger

Post by jvierra »

Set the listbox contents in the ComboBox "SelectedIndexChanged" event which is the default event for the ComboBox.
User avatar
saritM
Posts: 3
Last visit: Mon Feb 15, 2016 5:13 am

Re: ComboBox and ListBox trigger

Post by saritM »

can you please show me an example?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox and ListBox trigger

Post by jvierra »

Just load your listbox in the event.

I have no idea what you are trying to accomplish as you question is very vague:

Here are many examples of how to use a combobox. Perhaps I twill help. https://www.google.com/?gws_rd=ssl#neww ... n+combobox
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox and ListBox trigger

Post by jvierra »

The following is about the simplest example that I can come up with.
Attachments
Demo-SimpleComboRelation.psf
(21 KiB) Downloaded 210 times
User avatar
saritM
Posts: 3
Last visit: Mon Feb 15, 2016 5:13 am

Re: ComboBox and ListBox trigger

Post by saritM »

$combobox2_SelectedIndexChanged={
#TODO: Place custom script here
param (
[string]$DisplayMember_CB_LDST = ["LDST-TGB-BES01", "LDST-TGB-BES02"],
[string]$DisplayMember_CB_MAST = ["MAST-TGA-BES01", "MAST-TGA-BES02"]
)

if ($combobox1.SelectedIndex -eq "Staging")
{
if ($combobox2.SelectedIndex -eq "UK")
{
Load-ListBox -ListBox $listBox1 -Items $DisplayMember_CB_LDST
}
else
{
if ($combobox1.Items -eq "Staging")
{
if ($combobox2.Items -eq "Latam")
{
$checkedlistbox1.SelectedIndex = $DisplayMember_CB_MAST
}

}
}
}
}

this is my code.. im a beginner in PS so I guess im missing something
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox and ListBox trigger

Post by jvierra »

Sorry but your code does not make any sense to me. I recommend leaningPowerSHell before attempting to use forms. YOu APara statement is syntactically impossible and is throwing errors. Look up the help on each of these items and read the details.

I am sorry but a forum is not the right place to teach PowerShell. Search for books and sites teaching PowerSHell.

Here is one place to start: https://mva.microsoft.com/en-us/trainin ... 2304984382
This topic is 8 years and 1 month 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