Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim listCount As Integer = ListBox1.Items.Count
If listCount = 10 Then ListBox1.Items.RemoveAt(0)
ListBox1.Items.Add(Now.ToString)
End Sub
然后在ListChanged事件里面控制,到100的时候移除第一条
代码大概是这样的
private BindingList<string> _listSourcepublic BindingList<string> ListSource
{
get
{
return _listSource
}
set
{
_listSource = value
if (value != null)
{
value.ListChanged += Value_ListChanged
}
}
}
private void Value_ListChanged(object sender, ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded && _listSource.Count >= 100)
{
_listSource.RemoveAt(0)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)