Refresh Combobox function

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 5 years and 3 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
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Refresh Combobox function

Post by lontru »

Hi am tryin to create a function to update combobox but stuck in how to define the combobox

Update-ComboBox $combobox (Get-ChildItem "$Path" -Directory) "Name

How to pass the param $combobox to Update-ComboBox Comboxbox

and keep the $

RefreshCombobox -Combobox combobox_Vendor -Path "C:\SD"

pass the value as "combobox_Vendor" and i need it as $combobox_Vendor

is this possible?

Code below

Code: Select all


$CreateAppStructure_Load={
	#TODO: Initialize Form Controls here
	RefreshCombobox -Combobox combobox_Vendor -Path "C:\SD"
}

#region Control Helper Functions
#endregion

function RefreshCombobox ($combobox,$Path)
{
	Update-ComboBox $combobox_Vendor (Get-ChildItem "$Path" -Directory) "Name"	
}
Image

code sample for creating the folder for the form.

Code: Select all

New-Item c:\SD -ItemType Directory
1..10 | foreach {
$i++
New-Item c:\SD\Folder$($i) -ItemType Directory
}
Attachments
CreateAppStructure.psf
(156.84 KiB) Downloaded 139 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Refresh Combobox function

Post by jvierra »

Just use the correct variables.

Code: Select all

$CreateAppStructure_Load={
	#TODO: Initialize Form Controls here
	RefreshCombobox -Combobox $combobox_Vendor -Path C:\SD
}

function RefreshCombobox ($Combobox, $Path) {
    Update-ComboBox $Combobox (Get-ChildItem $Path -Directory) Name
}
[code]
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Refresh Combobox function

Post by lontru »

wierd i did the same thing but got error must been an typo :D
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Refresh Combobox function

Post by lontru »

I did some more work on the application but stuck on this wierd behavior.

The combobox vendor works fine when typing but the combobox product type ind wierd?

I recorded it in the gif. I type in test but get it backwards? as tset? have compare the to combobox and cant spot the different?
is the psf file damage/corrupt?

Image

attached the psf below.
Attachments
CreateAppStructure.psf
(92.78 KiB) Downloaded 172 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Refresh Combobox function

Post by jvierra »

Remove the extra attachment to the event under "properties changed"
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Refresh Combobox function

Post by lontru »

Is it this property?
Image

I have the same on the vendor combo box and i can type in fine there?
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Refresh Combobox function

Post by lontru »

hmm after i removed the "$combobox_Products_TextChanged" section i can type in normaly?

But i want the textchanged event on the combobox so i can check if the folder exist?

think i found the bug I clear the combobox under textchange

$combobox_Products.Items.Clear()

changed it to

$combobox_SoftwareVersion.Items.Clear()

and the gui function as i wanted

Code: Select all


	if (Test-Path -Path "$SDpath\$($combobox_Vendors.Text)\$($combobox_Products.Text)" -PathType Container)
	{
		$versions = Get-ChildItem -Path "$SDpath\$($combobox_Vendors.Text)\$($combobox_Products.Text)" | Select-Object -ExpandProperty Name
		foreach ($version in $versions)
		{
			if ($version -match '^[a-zA-Z]')
			{
				Update-ComboBox $combobox_Environments "$version" -Append
				$combobox_Environments.Enabled = $true
			}
			else
			{
				Update-ComboBox $combobox_SoftwareVersion "$version" -Append
				$combobox_SoftwareVersion.Enabled = $true
			}
		}
	}
	else
	{
		$combobox_Products.Items.Clear()
		$statusbar1.Text = "New vendor: $($combobox_Vendors.Text) - Fill out vendor name"
	}
This topic is 5 years and 3 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