GUI - Display data - table format - color? how?
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.
Re: GUI - Display data - table format - color? how?
Code: Select all
$button_export_data_Click={
#TODO: Place custom script here
$listview_sysinfo.Items | Select-Object -ExpandProperty SubItems |Export-Csv -Path "C:\tmp\LookupBug.txt"
}
Re: GUI - Display data - table format - color? how?
You have to extract the text of each subitem.
Code: Select all
$listview_sysinfo.Items |
select -expand SubItems |
select Name, Text
}
Re: GUI - Display data - table format - color? how?
Thanks a little side question: when runing the gui application. Can i access a terminal so i can debug what happening in the scriptjvierra wrote: ↑Fri Nov 09, 2018 2:38 am You have to extract the text of each subitem.
Code: Select all
$listview_sysinfo.Items | select -expand SubItems | select Name, Text }
Re: GUI - Display data - table format - color? how?
with above code i get every item in a list.jvierra wrote: ↑Fri Nov 09, 2018 2:38 am You have to extract the text of each subitem.
Code: Select all
$listview_sysinfo.Items | select -expand SubItems | select Name, Text }
I want to get it so i can pair the property and value together? on the same line?
How do i select columm `?
Re: GUI - Display data - table format - color? how?
That is just an example of what properties are on a ListViewItem. You need to use them to create a custom object and output that.
Start with an empty hash and add the "Name" and "Text" to the hash then convert to an object.
$hash = @{}
$Hash.Add{$_.Name,$_.Text}
After all subitems are added just co vert an output in one line:
[pscustomobject]$hash
Start with an empty hash and add the "Name" and "Text" to the hash then convert to an object.
$hash = @{}
$Hash.Add{$_.Name,$_.Text}
After all subitems are added just co vert an output in one line:
[pscustomobject]$hash
Re: GUI - Display data - table format - color? how?
Im going in circle what ever i do i get the a list out
How to i get the items and subitems... all value are under Text?
could you give some pointers
How to i get the items and subitems... all value are under Text?
Code: Select all
$button_export_data_Click = {
$Export_sysinfo = @()
$collection = $listview_sysinfo.Items | Select-Object -ExpandProperty SubItems | select Text
foreach ($items in $collection)
{
foreach ($item in $items)
{
$item | Out-File -FilePath "V:\outfile.txt" -Append
}
}
}
Re: GUI - Display data - table format - color? how?
Where is the hash? Where is the custom object?
You have to enumerate "Items" and "SubItems" and add the "Text" to the hash keyed by "Name". See above example of how to use a hash.
I wiIl search and see if I can find an example.
You have to enumerate "Items" and "SubItems" and add the "Text" to the hash keyed by "Name". See above example of how to use a hash.
I wiIl search and see if I can find an example.
Re: GUI - Display data - table format - color? how?
Well, as I suspected, no one seems to ever have decided to export the contents of a ListView. The issue is that ListView is not a data aware control and has no sense of data. It is just a bag of controls designed to allow different methods of viewing information. There are many third party ListView controls that support "data binding". Normally we would use one of those or crate a custom control to do this.
In PowerShell it is important to learn how to enumerate complex object collections, Once you can master this fundamental skill most things in PowerShell become much easier. To that end I will give you a mii tutorial.
First enumerate the "Items" collection and add the item to a new hash.
Next create a custom object from the hash and export it:
This gets you all of the items with the name used to create the item as the property and the text of the item as the value and create a collection of objects that are output to a Csv file. This is the classic "design pattern" for enumerating and exporting a complex object.
See: https://en.wikipedia.org/wiki/Software_design_pattern
All of the world of OOP (Object Oriented Programming) is implemented around this concept. Windows, the Net Framework and PowerShell are all object systems.
From the basic pattern we can now add a second level of generalization that we target at the "SubItems" collection to add it to our custom object. The total code required is on simple pipeline.
$_.SubItems | %{$hash.Add($_.Name,$_.Text)}{/b]
The full generalized implementation for exporting a ListView is as follows.
An easy way to work out these things is to export the PSF to a PS1 file and run with PowerShell. If you edit the exported ps1 and make the "$listview_sysinfo" variable a "global" it will persist after the form closes and you can then test manipulating this object interactively at a prompt. This method is a valuable tool for interactively inspecting and testing code against a complex object until you understand how you need to build the code in the form.
Good luck.
In PowerShell it is important to learn how to enumerate complex object collections, Once you can master this fundamental skill most things in PowerShell become much easier. To that end I will give you a mii tutorial.
First enumerate the "Items" collection and add the item to a new hash.
Code: Select all
$listview_sysinfo.Items |
ForEach-Object{
$hash = @{}
$hash.Add($_.Name,$_.Text)
}
}
Code: Select all
$listview_sysinfo.Items |
ForEach-Object{
$hash = @{}
$hash.Add($_.Name,$_.Text)
} |
Export-Csv $filename
See: https://en.wikipedia.org/wiki/Software_design_pattern
All of the world of OOP (Object Oriented Programming) is implemented around this concept. Windows, the Net Framework and PowerShell are all object systems.
From the basic pattern we can now add a second level of generalization that we target at the "SubItems" collection to add it to our custom object. The total code required is on simple pipeline.
$_.SubItems | %{$hash.Add($_.Name,$_.Text)}{/b]
The full generalized implementation for exporting a ListView is as follows.
Code: Select all
$listview_sysinfo.Items |
ForEach-Object{
$hash = @{}
$hash.Add($_.Name,$_.Text)
$_.SubItems | %{$hash.Add($_.Name,$_.Text)}
[pscustomobject]$hash
} |
Export-Csv $filename
Good luck.