Author Posts

February 22, 2016 at 11:57 am

i know this is probably really basic, but can't seem to find an easy answer on any searches.

i want to utilize a datagridview object as input for a script.

i can build up a datagridview, that is manually filled in by the users, however, once that is populated i can't find anywhere that describes straightforward now to loop through the contents, and how to extract the cells to use as variables elsewhere in the script.

February 22, 2016 at 12:03 pm

Really more of a .NET Framework question, not so much PowerShell. I used http://www.dotnetperls.com/datagridview-tutorial as a tutorial (which admittedly I originally found by Googling "datagridview tutorial") and adapted it from C#. But the DGV is really designed to be linked to a database so edits can be submitted to the back-end. You might also see if http://stackoverflow.com/questions/2581265/for-a-datagridview-how-do-i-get-the-values-from-each-row is helpful. Honestly, StackOverflow is going to be a better source for you on this, since it's all .NET.

I'll venture the opinion that PowerShell isn't the awesome-most GUI development environment. You might be happier in Visual Studio with C#, for example, if you're serious about this.

February 22, 2016 at 1:11 pm

Thanks Don, the stackoverflow article did get me over the hump.

just in case someone else out there tries to find this info, basic code that i got to work was:

($datagridview1 was the name of the datagridview in this particular script)


foreach ($DataGridViewRow in $datagridview1.Rows)
{
$variable = $DataGridViewRow.Cells["COLUMNNAME"].Value
}

obviously you can just call the value variable itself for utilization in the cmdlets