Author Posts

May 1, 2014 at 8:01 am

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.

May 1, 2014 at 11:45 am

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