How to scroll listview items programmatically

user3711357 picture user3711357 · Aug 4, 2014 · Viewed 11.7k times · Source

I have a listview control on my WinForms application.

here, on click of separate button, i do change couple of listview items backcolor and reload the whole grid as there are certain changes into database so, reloading from database on each click of button.

Now, problem is, once the grid is reloaded then lastly added items are scrolled so, need to scroll all items and find so, it makes hard to end user.

Is there any way to ,scroll the lastly added items or updated items into listview automatically (I mean, programmatically so, it could be view to user directly without being manually scrolled).

Answer

user3905907 picture user3905907 · Aug 4, 2014

listView1.EnsureVisible(X); where X is the item index.

This snippet can be used to scroll the ListView automatically to a particular index in the listView.

Consider the code: with this you can automatically scroll to the index 8 on button click

 private void button2_Click(object sender, EventArgs e)
 {
     listView1.EnsureVisible(8);
 }