Listbox items showing up as @{}

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
Locked
jkornhaus
Posts: 3
Joined: Sun Jul 07, 2019 3:16 pm

Listbox items showing up as @{}

Post by jkornhaus » Fri Jul 26, 2019 12:38 pm

Hi everyone,

version: Powershell Studio 2019 build 5.6.162
OS: Windows 10 x64
PS Version: 5.1.17763.316

I am practicing with the Powershell Studio and ran into an issue with the formatting of the items name.

If I use prepopulated items from the String Collection Editor, I can doubleclick an item to move it between both listboxes without any formatting issues with the items name.

When I run my get-process button, I am able to populate listbox 1 with the correct formatting. However, when I select what I want in listbox 1 and double click on it to move it over to listbox 2, the items show up as @{ProcessName=theitemiselected}

I have attached my listbox.psf to show what is going on.

Any help would be appreciated!
Attachments
listbox.psf
(33.22 KiB) Downloaded 17 times

jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Listbox items showing up as @{}

Post by jvierra » Fri Jul 26, 2019 1:28 pm

Like this:

Code: Select all

$listbox1_MouseDoubleClick=[System.Windows.Forms.MouseEventHandler]{
    #Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
    
        $listbox2.DisplayMember = $listbox1.DisplayMember
        $listbox2.Items.Add($listbox1.SelectedItem)
	$listbox1.Items.RemoveAt($listbox1.SelectedIndex)
}

jkornhaus
Posts: 3
Joined: Sun Jul 07, 2019 3:16 pm

Re: Listbox items showing up as @{}

Post by jkornhaus » Fri Jul 26, 2019 1:42 pm

Excellent! Thank you!

jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Listbox items showing up as @{}

Post by jvierra » Sat Jul 27, 2019 12:07 am

I found this old demo and changed it to use Get-Process. It shows a number of simple, standard methods for managing listboxes on a form.
Attachments
Demo-List2List.psf
(36.81 KiB) Downloaded 20 times

Locked