Hi
here's a sample with a combo box, it works quite the same as ListBox
$cb = new-object System.Windows.Forms.ComboBox
[void]$cb.Items.Add("powershell")
[void]$cb.Items.Add("rocks!")
$form.Controls.AddRange(@($cb,$OK))
$results = $form.showdialog()
write-host "SelectedItem=$($cb.SelectedItem)"
write-host "SelectedIndex=$($cb.SelectedIndex)"
More info on MSDN:
http://msdn2.microsoft.com/en-us/lib....combobox.aspx
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog:
http://blogs.microsoft.co.il/blogs/scriptfanatic Quote:
> Thanks Shay, is there a way to change this around to be a drop down
> list and how does one select more than one item? I tried to select
> both items supplied in the script and couldn't.
>
> regards,
>
> Anatoli
>
> "Shay Levi" wrote:
> Quote:
>> Hi
>>
>> I used Jeffery Snover's get-guiinput.ps1 script and added the listbox
>> code:
>>
>> [void][reflection.assembly]::LoadWithPartialName("System.Windows.Form
>> s")
>>
>> ###############################
>> # Create the form
>> $form = New-Object System.Windows.Forms.Form
>> $form.add_shown({$form.Activate()})
>> $form.Text = "PowerShell GUI Input"
>> $form.height = 110
>> ###############################
>> # Create the OK button and when the OK button is clicked hide the
>> form
>> $OK = new-object system.windows.forms.button
>> $OK.Text = "OK"
>> $OK.dock = "bottom"
>> $OK.Add_Click({
>> $form.hide()
>> })
>> $lb = new-object System.Windows.Forms.ListBox
>> [void]$lb.Items.Add("powershell")
>> [void]$lb.Items.Add("rocks!")
>> ###############################
>> # add the controls to the form
>> $form.Controls.AddRange(@($lb,$OK))
>> ###############################
>> # show the form
>> $results = $form.showdialog()
>> # show the results
>> $lb.SelectedItem
>> $lb.SelectedIndex
>> write-host "SelectedItem=$SelectedItem"
>> write-host "SelectedIndex=$SelectedIndex"
>> $form.dispose()
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
>> Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic Quote:
>>> Hi,
>>>
>>> Can someone kindly show me how to create a listbox where I can
>>> select multiple selections and pass them to a variable? I can't seem
>>> to find an example of this anywhere using powershell.
>>>
>>> thanks,
>>>