This example demonstrates how to programatically autoscroll WinForm controls TextBox, ListBox, ListView, TreeView and DataGridView.
Autoscroll to the end of box or view is useful, for example, in situations when you use one of these components as the output log window. Usually you add the items to the box or view and you want to be sure that the last added item is visible without the necessary to do it manually.
Though it's not difficult to solve this problem, .NET doesn't provide any unified way how to do it.
textBox1.SelectionStart = textBox1.Text.Length; textBox1.ScrollToCaret();
listBox1.SelectedIndex = listBox1.Items.Count - 1; listBox1.SelectedIndex = -1;
listView1.EnsureVisible(listView1.Items.Count - 1);
treeView1.Nodes[treeView1.Nodes.Count - 1].EnsureVisible();
dataGridView1.FirstDisplayedCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];