DataGridView: Value of first cell in Selected Row ToString

Welcome Forums General PowerShell Q&A DataGridView: Value of first cell in Selected Row ToString

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
4 years, 6 months ago.

  • Author
    Posts
  • #14919

    Participant
    Points: 1
    Rank: Member

    I have a DataGridView that allows the user to click on any row, and it selects the entire row as desired. However, I'm having an issue getting he value of the FIRST Cell in that Row that is selected to a string value.

    Previously when I only had 1 column being listed, it was easy:
    $SelectedRealm = $ProdRealmsdatagridview.CurrentCell.Value.ToString()

    Any help is appreciated.

  • #14932

    Participant
    Points: 0
    Rank: Member

    This is how I select values from a DataGridView

    $datagridview1_CellContentClick = [System.Windows.Forms.DataGridViewCellEventHandler]{
    #Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
    write-host $_.RowIndex # This displays the row number selected
    write-host $_.ColumnIndex # This displays the column number selected
    write-host $datagridview1.Rows[$_.RowIndex].Cells[0].value # This would display the value of the first cell in the selected row
    write-host $datagridview1.Rows[$_.RowIndex].Cells[$_.ColumnIndex].value # This would display the value of the cell selected
    }

    I hope that helps

The topic ‘DataGridView: Value of first cell in Selected Row ToString’ is closed to new replies.