ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'.

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 9 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
Dogeron
Posts: 5
Last visit: Fri Mar 22, 2024 6:00 am

ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'.

Post by Dogeron »

PowerShell Studio 2018
32 or 64 bit version of product: v5.5.152
Operating system: Windows 7
32 or 64 bit OS: 64
PowerShell : Platform: V5 64Bit (STA) (Elevated) (Forced)

I've been looking at this and just can't see what's wrong.....

Full Error Message :
ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'. The argument is null. Provide a valid value for the argument, and then try running the
ERROR: command again.
SingleForm_Test.psf (668, 49): ERROR: At Line: 668 char: 49
ERROR: + Update-ComboBox -ComboBox $cmbSelectEng -Items $a.Name
ERROR: + ~~~~~~~
ERROR: + CategoryInfo : InvalidData: (:) [Update-ComboBox], ParameterBindingValidationException
ERROR: + FullyQualifiedErrorId : ParameterArgumentValidationError,Update-ComboBox
The block of code is
  1. # Sort the data array in Mileage ASC
  2.     $GData  = $GData | Sort-Object  Mileage
  3.     #Just list the Name for the combobox
  4.     $a = $GData | Select-Object -Property Name
  5.     # Now push that into the combobox - leave -Append so it clears 1st
  6.     Update-ComboBox -ComboBox $cmbSelectEng -Items $a.Name
$GData is a System.Data.Datatable object built in code as it is reused, but can I simply assign it to the combobox instead of using this function call?

Finally can something be done with this webpage https://info.sapien.com/index.php/guis/ ... ox-control as it is somewhat confusing for Googling Powershell coders when Update-ComboBox is used instead.

Thanks.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'.

Post by mxtrinidad »

Instead of using $a.name, use " $a ".
$a already got the enum values, so the property ".Name" is not required.
User avatar
Dogeron
Posts: 5
Last visit: Fri Mar 22, 2024 6:00 am

Re: ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'.

Post by Dogeron »

@mxtrinidad

I've deleted the function and the combobox then inserted the combox ( now named combobox6) which forces the function to be re-inserted by Studio - just to make sure nothing crept into the function code.

Re-running as suggested gives.......
ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'. The argument is null. Provide a valid value for the argument, and then try running the
ERROR: command again.
SingleForm_Test.psf (675, 46): ERROR: At Line: 675 char: 46
ERROR: + Update-ComboBox -ComboBox $combobox6 -Items $a
ERROR: + ~~
ERROR: + CategoryInfo : InvalidData: (:) [Update-ComboBox], ParameterBindingValidationException
ERROR: + FullyQualifiedErrorId : ParameterArgumentValidationError,Update-ComboBox
ERROR:
For reference the 2 x tilda underlining actually starts at the whitespace before the $combobox6.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'.

Post by mxtrinidad »

The error states that $a is null. Because the one-liner error out. I can replicate the condition.
Make sure the variable is not null.

Code: Select all

## - this code will run!
$buttonCombo_Click={
	#TODO: Place custom script here
	$a = (Get-ChildItem).Name;
	
	## - Combo2 using SAPIEN Helper Functions:
	Update-ComboBox -ComboBox $combobox2 -Items $a;
}

Code: Select all

## - This code will Fail! $a is null
$buttonCombo_Click={
	#TODO: Place custom script here
	$a = (Get-ChildItem).Names;
	
	## - Combo2 using SAPIEN Helper Functions:
	Update-ComboBox -ComboBox $combobox2 -Items $a;
}
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'.

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
This topic is 5 years and 9 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