如何更新列表框? [英] How to update a listbox?
本文介绍了如何更新列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一直在尝试找到一些代码,这些代码将更新Windows窗体应用程序中的列表框,但是没有运气.
表单加载时,此代码将填充列表,效果很好:
Have been trying to find a bit of code that will update a listbox in a windows form application with no luck.
When form loads this code populates the list, which works just fine:
private void Form1_Load(object sender, EventArgs e)
{
lbItemsList.DataSource = shoppingBasket.OrderItems;
}
列表框"lbItemsList"绑定到一个名为"shoppingBasket"的类列表.当我将新项目添加到列表中,然后尝试再次运行同一行时,什么也没有发生.如何更新列表框?
我已经尝试过.Refresh()和.Update()方法,但它们都不起作用.
The listbox "lbItemsList" is binded to a class list called "shoppingBasket". When I add new items to the list then try to run the same line again, nothing happens. How can I update the listbox?
I''ve already tried the .Refresh() and .Update() methods and none of them work.
推荐答案
尝试此代码
try this code
lbItemsList.BeginUpdate();
lbItemsList.DataSource = null;
lbItemsList.DataSource = shoppingBasket.OrderItems;
lbItemsList.EndUpdate();
这篇关于如何更新列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文