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
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)
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
}
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.