Stumped, trying to get data from datagridview on click

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 3 years and 11 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
Russtoleum
Posts: 9
Last visit: Sat Nov 04, 2023 1:54 am

Re: Stumped, trying to get data from datagridview on click

Post by Russtoleum »

I appreciate your help tthus far and you have got me closer than before. This works with a single highlighted row:
$rowIndex = $ResultsDGV01.SelectedCells[0].Value

Which is great! Thank you.

But when I have multiple rows selected, $rowindex only holds the last row item selected.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stumped, trying to get data from datagridview on click

Post by jvierra »

I posted earlier that you need to use "SelectedRows" to get multiple rows.
Russtoleum
Posts: 9
Last visit: Sat Nov 04, 2023 1:54 am

Re: Stumped, trying to get data from datagridview on click

Post by Russtoleum »

I tried that and that was why I was getting the null error, when I changed it to selected row it worked. Which does what i want except it it pulls in the data for every column, I only want the data from the first row of the selected columns. I will try that again. My lack of knowledge is frustrating I'm sure, I appreciate your patience.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stumped, trying to get data from datagridview on click

Post by jvierra »

The property is a collection of row objects. It must be enumerated.
https://docs.microsoft.com/en-us/dotnet ... etcore-3.1
Russtoleum
Posts: 9
Last visit: Sat Nov 04, 2023 1:54 am

Re: Stumped, trying to get data from datagridview on click

Post by Russtoleum »

Even though I made this the most convoluted post ever, I think I should post this because this works for what I want:
$rowIndex = $ResultsDGV01.SelectedRows
$rowIndex |
ForEach-Object{
$row = $_.Cells[0].value
#$ResultsDGV01.Rows.Remove($row)
}
jvierra thank you so much, I was beating my head against the wall. I super appreciate it. Now I'm going to clean up my datagrid population methods. I hope this helps at least one other person.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stumped, trying to get data from datagridview on click

Post by jvierra »

Well - you are not close yet. Here is an example of how to manage a grid.

Note that if you hit the delete key you will delete a row and it will trigger a message from the event that manages deletes of data.

The code and how it works may be a bit challenging until you learn enough Pow3ershell and Forms coding to see why it works.
Attachments
Toolbox-Delete.psf
(14.67 KiB) Downloaded 85 times
Russtoleum
Posts: 9
Last visit: Sat Nov 04, 2023 1:54 am

Re: Stumped, trying to get data from datagridview on click

Post by Russtoleum »

Sweet, thank you. And my job is in system and network management, I'm doing this as an aside learning thing. I say that as an excuse for my lack of abilities thus far. And I don't plan to quit my day job.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stumped, trying to get data from datagridview on click

Post by jvierra »

No reason why you can't learn PowerShell. Just realize that it is a challenge for non-programmers until you learn the basics. Getting there takes a bit of time.

This book is a good place to start or to continue from.

https://www.sapien.com/books_training/W ... werShell-4
Russtoleum
Posts: 9
Last visit: Sat Nov 04, 2023 1:54 am

Re: Stumped, trying to get data from datagridview on click

Post by Russtoleum »

Thanks again for all your help. Good to have people like you on the internet.
This topic is 3 years and 11 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