I can't seem to get this to work?
if($CheckBoxList1.SelectedItem -eq "earth"){
..run code here
}
elseif($CheckBoxList1.SelectedItem -eq "wind"){
..run code here
}
elseif($CheckBoxList1.SelectedItem -eq "fire"){
..run code here
}
Am i missing something?
Checkboxlist selected items
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.
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.
Re: Checkboxlist selected items
Sorry I me meant to do something like this. What should the $items. be?
foreach ($items in $checkedlistbox1.SelectedItems)
{
if($items.('earth'))
{
Invoke-StoredProc1
}
elseif($items.('earth'))
{
Invoke-StoredProc2
}
}
foreach ($items in $checkedlistbox1.SelectedItems)
{
if($items.('earth'))
{
Invoke-StoredProc1
}
elseif($items.('earth'))
{
Invoke-StoredProc2
}
}
Re: Checkboxlist selected items
I have no idea what you put into the listbox. It could be full of anything.
Start here: http://www.sapien.com/blog/topics/spotl ... -controls/
Start here: http://www.sapien.com/blog/topics/spotl ... -controls/
Re: Checkboxlist selected items
If a box is loaded with strings like this:
PowerShell Code
Double-click the code block to select all.$FormEvent_Load={ $checkedlistbox1.Items.AddRange(@('earth','sky','moon'))` } $buttonGetItems_Click={ foreach($item in $checkedlistbox1.CheckedItems){ switch($item) { earth { [void][System.Windows.Forms.MessageBox]::Show('Earth is home to gnats' ) } sky { [void][System.Windows.Forms.MessageBox]::Show('The sky is the limit' ) } moon { [void][System.Windows.Forms.MessageBox]::Show('Moonbeams are seldom noisy') } } } }
Re: Checkboxlist selected items
the switch statement executes the moon only. I was looking to:
1. find all the checked ones in the checkboxlist
2. find the values of the checked ones then execute based on what the value is.
Thanks for your help.
1. find all the checked ones in the checkboxlist
2. find the values of the checked ones then execute based on what the value is.
Thanks for your help.
Re: Checkboxlist selected items
The switch statement is in a loop and executes for all checked items. I have used this code for years. Are you sure you know how to create the listbox?
Run the attached code to see what I mean.
Run the attached code to see what I mean.
- Attachments
-
- Demo-CheckedListbox.pff
- (5.28 KiB) Downloaded 405 times
Re: Checkboxlist selected items
My bad. It actually works. I had .selectedItems instead of .checkeditems
Thanks for the help
Thanks for the help
Re: Checkboxlist selected items
Good.
Once you see how controls are equipped things are pretty easy. It is the initial learning that can be very confusing. PowerShell Studio makes all of it much easier.
Once you see how controls are equipped things are pretty easy. It is the initial learning that can be very confusing. PowerShell Studio makes all of it much easier.