Get value of cell based on another cell from datagridview

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 2 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Get value of cell based on another cell from datagridview

Post by lontru »

Image

I know how to get selectedvalue from area 1 with : $datagridviewResultsLogs.SelectedCells[0].Value
but how do i get the value in area 2 when selecting cell from area 1 - the same row.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get value of cell based on another cell from datagridview

Post by jvierra »

Use the column name and not the index. The index is transient and the name always specifies the correct column.

$datagridviewResultsLogs.SelectedCells['Device'].Value
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Get value of cell based on another cell from datagridview

Post by lontru »

Code: Select all

$SelectedCell = $datagridviewResultsLogs.SelectedCells['Device'].Value
$SelectedLogfilename = $datagridviewResultsLogs.Rows[$($datagridviewResultsLogs.CurrentCell.RowIndex)].Cells[1].Value
$SelectedDevice = $datagridviewResultsLogs.Rows[$($datagridviewResultsLogs.CurrentCell.RowIndex)].Cells[0].Value
$script:selectedlogfile = "\\$SelectedDevice\$logdir\$SelectedLogfilename"
would above be the way to solve it or is there a better way
This topic is 2 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked