Using the ListView control Add-ListViewItem helper

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
PGomersall
Posts: 90
Joined: Sun Mar 03, 2013 12:40 pm

Using the ListView control Add-ListViewItem helper

Post by PGomersall » Mon Feb 03, 2014 12:28 pm

If the add a ListView control to a form a couple of helper items are added.
How would I use the "Add-ListViewItem" to populate the control from say using the following: (get-volume | select -property DriveLetter, FileSystemLabel). Playing around with the helper function I cannot get it to add anything. I am trying to add it via the form load event.
Pete

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Using the ListView control Add-ListViewItem helper

Post by davidc » Mon Feb 03, 2014 12:50 pm

Depends on what you wish to display and how.

If you want to display the drive letter and label you could try the following:

PowerShell Code
Double-click the code block to select all.
$volumes = get-volume 
foreach($drive in $volumes)
{
	Add-ListViewItem -ListView $listview1 -Items $drive.DriveLetter -SubItems $drive.FileSystemLabel
}
The ListView can be a complicated control. I recommend reading the Spotlight on the ListView control article:

http://www.sapien.com/blog/2012/04/04/s ... ol-part-1/

You can use a DataGridView as an alternative.

If you have further questions about using the GUI controls, we have a forum dedicated to the subject:

PowerShell GUIs

David
David
SAPIEN Technologies, Inc.

User avatar
PGomersall
Posts: 90
Joined: Sun Mar 03, 2013 12:40 pm

Re: Using the ListView control Add-ListViewItem helper

Post by PGomersall » Mon Feb 03, 2014 3:17 pm

David,
Tried the code you suggest, but it doesn't return any data to the ListView control.
Pete

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Using the ListView control Add-ListViewItem helper

Post by davidc » Mon Feb 03, 2014 5:04 pm

I didn't validate any of the fields or names. You will have to make sure you aren't using the wrong variable name.

I recommend running it through the debugger or just output the values.

David
David
SAPIEN Technologies, Inc.