Hi
I am using jvierra's excellent earlier post to copy data from Excel to a Datagridview from here:
viewtopic.php?t=9885
I have created a datagridview in the Designer.
I have not added or defined any columns.
My excel data has no headers.
The first column in spreadsheet is machine name
The second column is machine model
The data copies into the Datagridview fine. No problem.
I just can't do anything with it. I get white-space when I try to write-host a simple test and cannot operate on null values errors when I try to do anything:
$buttonTest_Click={
#TODO: Place custom script here
$datagridviewMachines.SelectAll()
$row = $datagridviewMachines.SelectedRows
foreach ($cell in $row.Cells)
{
$Name = $row.Cells['Column1'].Value
Write-Host $($Name)
$Model = $row.Cells['Column2'].Value
Write-Host $($Model)
}
}
Any ideas what I am doing wrong?
thanks
Datagridview - Pasting from Excel Help
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
-
- Posts: 14666
- Joined: Tue May 22, 2007 9:57 am
- Has voted: 1 time
- Been upvoted: 5 times
- Contact:
Re: Datagridview - Pasting from Excel Help
The spreadsheet must have headers or you must predefine the columns.