Page 1 of 1

Refresh Combobox function

Posted: Sat Dec 08, 2018 4:32 am
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
}

Re: Refresh Combobox function

Posted: Sat Dec 08, 2018 11:15 am
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]

Re: Refresh Combobox function

Posted: Sat Dec 08, 2018 2:24 pm
by lontru
wierd i did the same thing but got error must been an typo :D

Re: Refresh Combobox function

Posted: Tue Dec 11, 2018 3:25 pm
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.

Re: Refresh Combobox function

Posted: Tue Dec 11, 2018 4:09 pm
by jvierra
Remove the extra attachment to the event under "properties changed"

Re: Refresh Combobox function

Posted: Wed Dec 12, 2018 1:32 am
by lontru
Is it this property?
Image

I have the same on the vendor combo box and i can type in fine there?

Re: Refresh Combobox function

Posted: Wed Dec 12, 2018 1:39 am
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"
	}