Load-ComboBox Question

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.
This topic is 10 years and 11 months 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.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load-ComboBox Question

Post by jvierra »

Yes - you are adding the list twice it seems:
PowerShell Code
Double-click the code block to select all.
Load-ComboBox $listLogs (Get-ChildItem -Path "C:ProgramDataAgentLogs" -Recurse -Include *.log) "Name"
This should be:
PowerShell Code
Double-click the code block to select all.
$items=Get-ChildItem -Path C:ProgramDataAgentLogs -Recurse -Include *.log
Load-ComboBox $ListLogs $items 'Name'
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load-ComboBox Question

Post by jvierra »

Sorry - I messed up the edit in the last post. It should be fixed now.

The way I laid this out it should not duplicate. Check the folders. You are using recurse and there could be subfolders with identically named files.
User avatar
Lery154
Posts: 48
Last visit: Fri Feb 20, 2015 12:36 pm

Re: Load-ComboBox Question

Post by Lery154 »

Update. I've been able to get the ComboBox to populate correctly using the following instead of what I was using:
PowerShell Code
Double-click the code block to select all.
$OnLoadFormEvent={
	Load-ComboBox $listLogs (Get-ChildItem -Path "C:ProgramData\AgentLogs" | Where-Object {$_.Name})
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load-ComboBox Question

Post by jvierra »

Then this should work too:
PowerShell Code
Double-click the code block to select all.
#
$items=Get-ChildItem -Path C:ProgramDataAgentLogs -Recurse -Include *.log
Load-ComboBox $ListLogs $items 'Name'
#
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load-ComboBox Question

Post by jvierra »

Where-Object is a filter. It will not filter out duplicates.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load-ComboBox Question

Post by jvierra »

It was removing the 'recurse' parameter that fixed you. The Where-Object does nothing.

I think you might do well to take some time to do a course on PowerShell. Guessing your way through this will be very frustrating.
This topic is 10 years and 11 months 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.
Locked