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.
Locked
User avatar
stevens
Posts: 451
Last visit: Fri Jul 02, 2021 1:35 am
Has voted: 1 time

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: 14867
Last visit: Fri Jul 23, 2021 7:52 pm
Answers: 12
Has voted: 3 times
Been upvoted: 10 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

Locked