Refresh Gridview, focus on row selected in middle of grid (scrollbar)

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 1 month 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
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Refresh Gridview, focus on row selected in middle of grid (scrollbar)

Post by stevens »

Hi,

I have a refresh of a gridview after which I select again the row which was selected for the refresh. That works fine.

However, the gridview has a long list of values, so when I select a value in the middle of the list and the scrollbar (vertical) is there and I do a refresh, the gridview should scroll to that value but it is not.
How can I do this, something like $datagridview01.Rows[$RowToSelect].Selected = $true for row then $datagridview01.Rows[$RowToSelect].SCROLLTOROW = $True?

Hope this is clear.
Please advise.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Refresh Gridview, focus on row selected in middle of grid (scrollbar)

Post by jvierra »

https://docs.microsoft.com/en-us/dotnet ... ngRowIndex

$dataGridView1.FirstDisplayedScrollingRowIndex = $dataGridView1.SelectedRows[0].Index
This topic is 3 years and 1 month 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