问题描述
我有一个 C# Windows 窗体项目,其中包含一个包含 2 个列表框和一个按钮的窗体.在 FormLoad 上,左侧 ListBox 填充了一个列表(大约 1800 项),其中包含有关证券(ID 和名称)的信息,当用户单击该按钮时,所有证券都会从左侧列表框移到右侧.
I have a C# Windows Forms project with a Form containing 2 ListBoxes and a button. On FormLoad the left ListBox is filled with a list (about 1800 items) containing information about Securities (ID and Name) and when the user clicks on the button all the securities are moved from the left listbox to the right.
当我不使用 BindingSources 时,即我直接使用 ListBoxes 的 Items 属性时,移动过程需要几秒钟:
When I'm not using BindingSources, i.e. I'm directly using the Items property of the ListBoxes the moving process takes a few seconds:
private void button1_Click(object sender, EventArgs e)
{
while (listBox1.Items.Count > 0)
{
Security s = listBox1.Items[0] as Security;
listBox1.Items.Remove(s);
listBox2.Items.Add(s);
}
}
但是,当我使用 BindingSources 时,它需要几分钟:
But, when I'm using BindingSources it takes several minutes:
listBox1.DataSource = bindingSource1;
listBox2.DataSource = bindingSource2;
...
private void MainForm_Load(object sender, EventArgs e)
{
ICollection<Security> securities = GetSecurities();
bindingSource1.DataSouce = securities;
}
private void button1_Click(object sender, EventArgs e)
{
while (bindingSource1.Count > 0)
{
bindingSource1.Remove(s);
bindingSource2.Add(s);
}
}
BindingSource 方式需要这么长时间的原因是什么?有什么办法让它更快?
What's the reason for the BindingSource-way to take so much longer? Is there any way to make it faster?
推荐答案
好的,解决了.我必须操作底层集合,然后在最后重置绑定.现在它几乎立即移动:)
Ok, solved it. I have to manipulate the underlying collection and then reset bindings at the end. Now it's almost instantly moving :)
这篇关于使用 BindingSource 很慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)