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 LICENSE NUMBERS, ACTIVATION 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.
This topic is 10 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
PGomersall
Posts: 131
Last visit: Thu Feb 15, 2024 12:14 pm

Using the ListView control Add-ListViewItem helper

Post by PGomersall »

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
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Using the ListView control Add-ListViewItem helper

Post by davidc »

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: 131
Last visit: Thu Feb 15, 2024 12:14 pm

Re: Using the ListView control Add-ListViewItem helper

Post by PGomersall »

David,
Tried the code you suggest, but it doesn't return any data to the ListView control.
Pete
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Using the ListView control Add-ListViewItem helper

Post by davidc »

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.
This topic is 10 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.