I am trying to capture the selected cells in a datagridview, using a multi-select datagrid. So far I have something like this, although not working..
$selections = $datagridview1.SelectedCells()
foreach ($item in $selections)
{
Do stuff
}
Datagridview selected cells
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.
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
Re: Datagridview selected cells
You need to use the property as there is no method with that name. Look closely at the documentation.
foreach($item in $datagridview1.SelectedCells){
Do stuff
}
There is no "SelectedCells()"
foreach($item in $datagridview1.SelectedCells){
Do stuff
}
There is no "SelectedCells()"
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
Re: Datagridview selected cells
Ok, that much I figured out when the code I tried didn't work.. So I am aware of that much up to this point. When the program is run, and the datagrid populates the data I am having fed to it from a powershell query, a user will be able to click on those results.. Screen shot below..
https://1drv.ms/u/s!AgBAbImA7NSlsxyQnBdWjslyeHA8
My question is, when a user clicks on a cell, I want to take the value of the cell or cell(s) clicked and do something with it. That is where I am struggling.
https://1drv.ms/u/s!AgBAbImA7NSlsxyQnBdWjslyeHA8
My question is, when a user clicks on a cell, I want to take the value of the cell or cell(s) clicked and do something with it. That is where I am struggling.
- Shelltastic
- Posts: 65
- Last visit: Mon Feb 19, 2024 11:31 am
Re: Datagridview selected cells
Disregard please. I was able to get the selected cell value by using $datagridview1.SelectedCells[0].Value
Thank you for the response.
Thank you for the response.
Re: Datagridview selected cells
What is the issue.? The code enumerates all cells selected.
To access a cell on a click use the "CellClick" or "CellContentClick" event. The event object contains the cell column and row indexes.
To access a cell on a click use the "CellClick" or "CellContentClick" event. The event object contains the cell column and row indexes.