Page 1 of 1

DataGridView: Value of first Cell in Selected Row

Posted: Thu May 01, 2014 8:11 am
by Eurisko
I searched for this, but didn't find anything in the first 15 pages of search results. :)

I have a DataGridView that I have setup so when you click, it selects the entire Row.

How do I get the value to a string of the FIRST cell in the row that is selected?

Re: DataGridView: Value of first Cell in Selected Row

Posted: Thu May 01, 2014 8:57 am
by jvierra
PowerShell Code
Double-click the code block to select all.
$datagridview1_CellContentClick=[System.Windows.Forms.DataGridViewCellEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
    $cell=$datagridview1.Rows[$_.RowIndex].Cells[$_.ColumnIndex].Value
    [void][System.Windows.Forms.MessageBox]::Show($cell,"test")
}

Re: DataGridView: Value of first Cell in Selected Row

Posted: Thu May 01, 2014 9:14 am
by jvierra
Here is the same thing in the row changed event:
PowerShell Code
Double-click the code block to select all.
$datagridview1_SelectionChanged={
    $r=$datagridview1.SelectedRows[0].Cells[0].Value
    [void][System.Windows.Forms.MessageBox]::Show($r,"test")
}

Re: DataGridView: Value of first Cell in Selected Row

Posted: Thu May 01, 2014 9:35 am
by Eurisko
Unfortunately that only gives me the cell clicked on in the row. I actually need the first cell in the row, regardless of the cell clicked in the row. Does that make sense?

EDIT: Actually, the second option you listed did the trick. Thanks!