Looking for a way to grab the cell adjacent to the user selection in my Datagridview.
I am using "$Selection = $datagridview1.SelectedCells[0].Value" to get the selected cell, but not sure what I can use to grab the cell next to it also, as I will need both values.
Datagridview Selection
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
Re: Datagridview Selection
Am I missing something? Using the following...
$DisplayName = $datagridview1.SelectedCells[0].Value
$Database = $datagridview1.Row[$DisplayName.RowIndex].Cell[$DisplayName.CellIndex + 1]
$DisplayName = $datagridview1.SelectedCells[0].Value
$Database = $datagridview1.Row[$DisplayName.RowIndex].Cell[$DisplayName.CellIndex + 1]
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
Re: Datagridview Selection
Looks like I am still failing. I need to get the adjacent cells value, not just index, looks like I didn't mention that in my original post. Attachments included.
- Attachments
-
- 2.PNG (17.19 KiB) Viewed 2361 times
-
- 1.PNG (4.73 KiB) Viewed 2361 times
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
Re: Datagridview Selection
It doesn't even appear to get the adjacent cell. I get that error when I run the code you suggested verbatim.
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
Re: Datagridview Selection
Disregard, I was able to figure it out. I just manually get the RowIndex and grab the next cell over from the selection, kept it simple. For reference I am using the code below, thanks for the assistance.
Code: Select all
$cell = $datagridview1.SelectedCells[0]
$RowIndex = $cell.RowIndex
$adjacent = $datagridview1.Rows[$RowIndex].Cells[1].Value