how do i utilize datagridview data as input for a script

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of David Schmidtberger David Schmidtberger 9 months, 3 weeks ago.

  • Author
    Posts
  • #35525
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

    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.

  • #35526
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #35530
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

    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

You must be logged in to reply to this topic.