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.
Locked
User avatar
lontru
Posts: 73
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Fri Aug 18, 2017 4:36 am

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 41 times

jvierra
Posts: 14438
Joined: Tue May 22, 2007 9:57 am
Contact:

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: 73
Joined: Fri Aug 18, 2017 4:36 am

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: 73
Joined: Fri Aug 18, 2017 4:36 am

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 59 times

jvierra
Posts: 14438
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Refresh Combobox function

Post by jvierra »

Remove the extra attachment to the event under "properties changed"

User avatar
lontru
Posts: 73
Joined: Fri Aug 18, 2017 4:36 am

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: 73
Joined: Fri Aug 18, 2017 4:36 am

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"
	}

Locked