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

Refresh Combobox function

Post by lontru » Sat Dec 08, 2018 4:32 am

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

User avatar
jvierra
Posts: 13463
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Refresh Combobox function

Post by jvierra » Sat Dec 08, 2018 11:15 am

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

Re: Refresh Combobox function

Post by lontru » Sat Dec 08, 2018 2:24 pm

wierd i did the same thing but got error must been an typo :D

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

Re: Refresh Combobox function

Post by lontru » Tue Dec 11, 2018 3:25 pm

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

User avatar
jvierra
Posts: 13463
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Refresh Combobox function

Post by jvierra » Tue Dec 11, 2018 4:09 pm

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

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

Re: Refresh Combobox function

Post by lontru » Wed Dec 12, 2018 1:32 am

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

Re: Refresh Combobox function

Post by lontru » Wed Dec 12, 2018 1:39 am

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