
Originally Posted by
.paul.
this works:
vb.net Code:
ListBox1.Items.Add("new item")
Dim maxItems As Integer = ListBox1.Height \ ListBox1.GetItemHeight(0)
ListBox1.TopIndex = ListBox1.Items.Count - maxItems
You don't need to calculate the number of items that will fit in the ListBox.
Code:
Imports System.ComponentModel
Public Class Form1
Dim MyBindingList As BindingList(Of String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MyBindingList = New BindingList(Of String) From {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"}
ItemsListBox.DataSource = MyBindingList
End Sub
Private Sub InsertButton_Click(sender As Object, e As EventArgs) Handles InsertButton.Click
MyBindingList.Add("New Item")
ItemsListBox.TopIndex = ItemsListBox.Items.Count - 1
End Sub
End Class