Bart
2007-06-14 20:11:28 UTC
Hi,
I'm having trouble passing an combobox object as a function argument. The objhect seems to be referring to a null value when I try to access the methods.
Do I need to cast this in a special way?
There is no problem filling the combo with the array outside the function.
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | out-null
Function Initialise_Combo([System.object]$combo,[array]$list)
{ #args[0] ref to combo
#args[1] ref to items array
$combo.items.addrange($list)
}
...
# create form
$form = new-object System.Windows.Forms.form
$form.Text = "Workstation Profile Picker"
$form.size = new-object System.Drawing.Size(500,400)
# Add dept and roles combo
$DeptDrop = new-object System.Windows.Forms.ComboBox
$DeptDrop.Location = new-object System.Drawing.Size(10,30)
$DeptDrop.Size = new-object System.Drawing.Size(80,30)
$DeptDrop.Sorted = 1
$form.Controls.Add($DeptDrop)
.... some code to create and initialise the hash...
.... some code to activate the form
# this works
$DeptDrop.Items.addrange([array]$hash_dept.psbase.values)
#this doesn't work ($combo seems to be pointing to a null value)
Initialise_Combo($DeptDrop,[array]$hash_dept.psbase.values)
Anyone?
Kind regards,
Bart.
I'm having trouble passing an combobox object as a function argument. The objhect seems to be referring to a null value when I try to access the methods.
Do I need to cast this in a special way?
There is no problem filling the combo with the array outside the function.
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | out-null
Function Initialise_Combo([System.object]$combo,[array]$list)
{ #args[0] ref to combo
#args[1] ref to items array
$combo.items.addrange($list)
}
...
# create form
$form = new-object System.Windows.Forms.form
$form.Text = "Workstation Profile Picker"
$form.size = new-object System.Drawing.Size(500,400)
# Add dept and roles combo
$DeptDrop = new-object System.Windows.Forms.ComboBox
$DeptDrop.Location = new-object System.Drawing.Size(10,30)
$DeptDrop.Size = new-object System.Drawing.Size(80,30)
$DeptDrop.Sorted = 1
$form.Controls.Add($DeptDrop)
.... some code to create and initialise the hash...
.... some code to activate the form
# this works
$DeptDrop.Items.addrange([array]$hash_dept.psbase.values)
#this doesn't work ($combo seems to be pointing to a null value)
Initialise_Combo($DeptDrop,[array]$hash_dept.psbase.values)
Anyone?
Kind regards,
Bart.