CuriousOne
CuriousOne

Reputation: 962

Copy all Listbox items to a array

I have a listbox that contains PSObjects like this:

$obj = New-Object -TypeName PSObject -Property @{
  'Name' = 'SueAnne'
  'Region'= 'Northern'
}

The listbox looks like this (I set the $listbox.DisplayMember = 'name'):

|SueAnne  |
|Marge    |
|Rocky    |

None of the listbox items are selected and I need to be able to copy the listbox items to an array. This works if the listbox items were selected

$tempList = $listbox.SelectedItems
write-host $tempList[0..1]   #output just the first 2 items

@{Name=SueAnne; Region=Northern} @{Name=Marge; Region=Southern}

But since they aren't selected is there a way to do this without looping through each item in the listbox?

Upvotes: 0

Views: 1352

Answers (1)

Matt
Matt

Reputation: 46730

Pretty sure you are just looking for ListBox.Items

This property enables you to obtain a reference to the list of items that are currently stored in the ListBox.

So in your case the array you are looking for comes from $listbox.Items.

Upvotes: 0

Related Questions