Pezzzz Pezzzz - 1 year ago 130 Question

How to a scroll a listbox to see the last item added, on event

I have a single line textbox that is used to add numerical strings to a checked listbox. I want the listbox to auto scroll to the last item added if this is not visible to the user. I have looked for scroll properties of the listbox but I can't find anything that looks like it will scroll the listbox.

Does anyone have any advice?

Here is the code that adds an item to the listbox:

Private Sub bttAddchklstDbManagement_Click(sender As System.Object, e As System.EventArgs) Handles bttAddchklstDBmanagement.Click
If Not txtDBManagement.Text = Nothing And Not txtDBManagement.Text = "" Then
chklstDBmanagement.SetItemChecked(chklstDBmanagement.Items.Count - 1, True)
txtDBManagement.Text = Nothing
End If
End Sub

txtDBmanagement is the TextBox

chklstDbManagement is the checked listbox

Answer Source

Use TopIndex after adding the item.

    private void button1_Click(object sender, EventArgs e)
        checkedListBox1.TopIndex = checkedListBox1.Items.Count - 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download