CSV import

This topic contains 4 replies, has 2 voices, and was last updated by  Rawdogz 10 months, 1 week ago.

  • Author
    Posts
  • #61677

    Rawdogz
    Participant

    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.
  • #61678

    Rob Simmers
    Participant

    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
    }
    
    • #61758

      Rawdogz
      Participant

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

  • #61759

    Rob Simmers
    Participant

    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

    • #61926

      Rawdogz
      Participant

      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.

You must be logged in to reply to this topic.