I am trying to use the Winforms BindingSource control from PowerShell but I get a very strange result. If I put some data in a datatable called $Data for example and include these lines:
$Bs = New-Object System.Windows.Forms.BindingSource
$Bs.DataSource = $Data
in a script which fills the datatable and then assigns $Bs to the datasource of a control such as a listbox it works as expected.
However, if I put these lines in a function such as
FUNCTION fun
{
param ($D)
$B = New-Object System.Windows.Forms.BindingSource
$B.DataSource = $D
return $B
}
and then call the function with
$Bs = Fun -D $Data
it doesn't work. I have checked and checked that the two lines in the function are the same as the two lines in the script but there are no differences.
When I have the two lines in the main body of the script I get a list of towns which is what I would expect. When I put the same lines in the function the list box displays the correct number of rows but instead of the names of each town it displays "System.Data.DataRowView".
Is it the case that it just isn't possible in PowerShell to return a BindingSource from a function?
Best wishes....
Colin Bruce