Author Posts

January 10, 2017 at 11:48 pm

hello everyone

I am looking for a little help in getting a CSV to import and show in a listview box in detail view with about 2 to 3 columns. I am using powershell studio.

The below button allow me to pick the CSV and the file location becomes visible in the $textboxfile.text

 
$buttonBrowse_Click={
	if($openfiledialog1.ShowDialog() -eq 'OK')
	{
		$textboxFile.Text = $openfiledialog1.FileName
	}
		$file = $openfiledialog1.FileName
	}

This button when clicked should import that CVS into the $listView1 in detail view, with the columns from the CSV.(this is the part I am having issue with)

$buttonSingleClick_Click={
	$this.Enabled = $False
	$list = Import-Csv $file
	$rows = Import-Csv -Path $list
	$table = ConvertTo-DataTable -InputObject $rows
	
        Load-DataGridView -DataGridView $listview1 
		
	[System.Windows.Forms.Application]::DoEvents()
	$this.Enabled = $True
}


thank you for any help.

January 11, 2017 at 3:08 am

Seems like you are overcomplicating things a bit. If you save the path in the textbox, it's redundant to set another variable. Import-CSV was being called twice, so we just need to call it once and pass the path in the textbox object. Lastly, you don't need to convert the PSObject to a DataTable, you should able to pass that object directly to Load-DataGridView. See if these updates work for you:

$buttonBrowse_Click = {
	if ( $openfiledialog1.ShowDialog() -eq 'OK' ) {
		$textboxFile.Text = $openfiledialog1.FileName
	}
}

$buttonSingleClick_Click = {
	$this.Enabled = $False
	#Load the CSV from the textbox since you fill it
    $csv = Import-Csv -Path $textboxFile.Text
	#Load the ListView1 object with the CSV
    Load-DataGridView -DataGridView $listview1 -Item $csv
		
	[System.Windows.Forms.Application]::DoEvents()
	$this.Enabled = $True
}

January 11, 2017 at 11:35 pm

Thank Rob, Getting a error now "The term 'Load-DataGridView' is not recognized as the name of a cmdlet......"

January 12, 2017 at 1:48 am

Load-DataGridView is a helper function most likely included with Sapien Powershell Studio, which you said you were using PowerShell Studio. An example can be found here: http://www.lazywinadmin.com/2013/10/PowerShellStudio2012ToolMaking.html

January 14, 2017 at 6:09 pm

Thank Rob, that article helped me to find out where i made my mistake. I started off using datagrid then i moved over to listview as I got the part I was working on to work, but left the Datagrid helper in that button code.

What i really trying to do then is to get the CVS to import to the $lstfrom, listview box.