Public/Import-WFDataGridView.ps1

function Import-WFDataGridView
{
    <#
    .SYNOPSIS
        This functions helps you load items into a DataGridView.
 
    .DESCRIPTION
        Use this function to dynamically load items into the DataGridView control.
 
    .PARAMETER DataGridView
        The ComboBox control you want to add items to.
 
    .PARAMETER Item
        The object or objects you wish to load into the ComboBox's items collection.
     
    .PARAMETER DataMember
        Sets the name of the list or table in the data source for which the DataGridView is displaying data.
     
    .EXAMPLE
        Import-WFDataGridView -DataGridView $DataGridView1 -Item (Get-Process)
     
    .NOTES
        Based on Load-DataGridView function from:
        SAPIEN Technologies, Inc.
        http://www.sapien.com/
         
    #>

    
    Param (
        [ValidateNotNull()]
        [Parameter(Mandatory = $true)]
        [System.Windows.Forms.DataGridView]$DataGridView,
        
        [ValidateNotNull()]
        [Parameter(Mandatory = $true)]
        $Item,
        
        [Parameter(Mandatory = $false)]
        [string]$DataMember
    )
    BEGIN
    {
        Add-Type -AssemblyName System.Windows.Forms
    }
    PROCESS
    {
        $DataGridView.SuspendLayout()
        $DataGridView.DataMember = $DataMember
        
        if ($Item -is [System.ComponentModel.IListSource]`
        -or $Item -is [System.ComponentModel.IBindingList] -or $Item -is [System.ComponentModel.IBindingListView])
        {
            $DataGridView.DataSource = $Item
        }
        else
        {
            $array = New-Object System.Collections.ArrayList
            
            if ($Item -is [System.Collections.IList])
            {
                $array.AddRange($Item)
            }
            else
            {
                $array.Add($Item)
            }
            $DataGridView.DataSource = $array
        }
    }
    END
    {
        $DataGridView.ResumeLayout()
    }
}