Page 2 of 2

Re: Datagridview Selection

Posted: Mon Apr 20, 2020 7:51 am
by jvierra
That is because you didn't want the adjacent cell you wanted a specific cell.

Just change one value in my code and extract the value.

Code: Select all

$cell = $datagridview1.SelectedCells[0]
$Database = $datagridview1.Row[$cell.RowIndex].Cell[$cell.ColumnIndex + 1].Value
Also adjacent means either current column index + 1 or current column index -1

Posting pictures of code made it hard for me to read teh error and your code. THe issue is fixed here:

Re: Datagridview Selection

Posted: Mon Apr 20, 2020 8:06 am
by Shelltastic
Correction, I DO want the adjacent cell from the selected cell. See screen shot below. The blue cell is the selected cell, the red arrow points to the cell's value I also need to grab along with the selected cell, hence, I need the "adjacent" cell. In my scenario, the adjacent cell will always be to the right of the selected cell due to the way the datagrid loads, so the code I posted above gets me the desired result every time.

Once again, thank you for the assistance.

Re: Datagridview Selection

Posted: Mon Apr 20, 2020 8:24 am
by jvierra
"Adjacent" can be either left or right of the current cell.

To get a specific cell use its name.

$Database = $datagridview1.Row[$cell.RowIndex].Cell['ServerName'].Value