I'm reading in an array of pscustomobjects from json files.
They appear to be loading into the listbox with $listbox.DataSource
However, the displaymember values never reflect the designated "name" property value. It's always the raw object data
over simplified code:
function:
foreach($file in $files)
{
$item = Get-Content -Path $file.fullname | ConvertFrom-Json
$items += $item
return $items
}
Feeds:
$listbox.DataSource = $items
$listbox.DisplayMember = "name" #I have tried 'name' as well
Here's a screenshot of the object in the debugger:
The listbox populates with the raw data, rather than the name value. Notice the name resolves and loads fine in the 'type name' field
It's odd that the name property appears to be lost in the displaymember setting
Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.207
OS: Windows 10 Pro for Workstations (64 Bit)
Build: v10.0.19044.0
Listbox Displaymember: odd results
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.
-
- Posts: 2
- Last visit: Mon May 22, 2023 9:31 am
Listbox Displaymember: odd results
This is what is needed to convert an array into an iList collection.
$listbox.DataSource = [system.collections.arraylist]$items
Go to full post$listbox.DataSource = [system.collections.arraylist]$items
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Listbox Displaymember: odd results
[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
-
- Posts: 2
- Last visit: Mon May 22, 2023 9:31 am
Re: Listbox Displaymember: odd results
Yesss!!! Thank you!
You know I swear when I first ran this I got a warning about that and I did something like change $items to @($Items) and the error went away. I changed back while goofing around and never saw it again
You know I swear when I first ran this I got a warning about that and I did something like change $items to @($Items) and the error went away. I changed back while goofing around and never saw it again