According to Sapien guidance this should work
[ListViewSubItem] Add ([String] text, [Color] foreColor, [Color] backColor, [Font] font)
I can add a string no problem but cannot get foreColor to work - does anyone have an example - Spaien only lists this:
$subItem = $listitem.SubItems.Add('Installed')
ListView items set forecolor
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: ListView items set forecolor
If I remember correctly you will have to create ne3w2 color objects and font objects so the objects are references and not static objects. The API ignores these if they are of the wrong type.
$c = [system.drawing.color]::FromKnownColor('Black')
Here is another way to add colored items:
$c = [system.drawing.color]::FromKnownColor('Black')
Here is another way to add colored items:
Code: Select all
$items=@(
[PSCustomObject]@{ Text = 'This is red';Color='Red'}
[PSCustomObject]@{ Text = 'This is blue'; Color = 'Blue' }
[PSCustomObject]@{ Text = 'This is green'; Color = 'Green' }
)
$listbox1.Items.AddRange($items)
Re: ListView items set forecolor
Also note that this works:
$lvsi = [System.Windows.Forms.ListViewItem+ListViewSubItem]::new($lvi,'hello world','Red','black','TImes')
Your example is missing the owner which is required on subitems. ListviewSubItem does not have an "Add" method so I suspect you have other mistakes in your code.
The following also works:
$lvsi = $lvi.SubItems.Add('Hello World','Red','Black','Times')
Where $lvi is a ListViewItem.
$lvsi = [System.Windows.Forms.ListViewItem+ListViewSubItem]::new($lvi,'hello world','Red','black','TImes')
Your example is missing the owner which is required on subitems. ListviewSubItem does not have an "Add" method so I suspect you have other mistakes in your code.
The following also works:
$lvsi = $lvi.SubItems.Add('Hello World','Red','Black','Times')
Where $lvi is a ListViewItem.
-
- Posts: 3
- Last visit: Sun Apr 07, 2024 11:17 am
Re: ListView items set forecolor
jvierra
Thank you very much - i must have missed something when applying this to the subitem although the string worked which was the puzzling part. I'll look more closely at what i coded and the example you gave. Thanks again.
Thank you very much - i must have missed something when applying this to the subitem although the string worked which was the puzzling part. I'll look more closely at what i coded and the example you gave. Thanks again.
-
- Posts: 6
- Last visit: Tue Feb 02, 2021 11:54 pm
Re: ListView items set forecolor
Thanks! You helped me a lot.jvierra wrote: ↑Tue Jan 19, 2021 11:36 am
Here is another way to add colored items:Code: Select all
$items=@( [PSCustomObject]@{ Text = 'This is red';Color='Red'} [PSCustomObject]@{ Text = 'This is blue'; Color = 'Blue' } [PSCustomObject]@{ Text = 'This is green'; Color = 'Green' } ) $listbox1.Items.AddRange($items)