问题描述
我想知道哪种方法是填充WinForm的ListBox控件的最佳方法,该控件取决于无线电btn?
I'm wondering what would be the best way to populate a ListBox control of a WinForm, populated depending on a radio btn?
我已经看到一些建议,可以使用foreach遍历列表的每个对象,然后将它们添加()到listBox.items.Add(),但这似乎是一个非常糟糕的主意,因为来自rabio btn 1返回具有10.000条记录的列表(花一些时间进行循环,并且UI在循环时冻结,这是一个糟糕的主意).
I have seen some suggestions to use a foreach to loop over each object of my list, and Add() them to the listBox.items.Add(), but this seems to be a really bad idea, since the list from rabio btn 1 returns a list with 10.000 records (takes quiet some time to loop over, and the UI freeze while looping, bad bad idea).
有没有更好的方法可以做到这一点,也许在单独的Task中可以阻止UI冻结?
Is there any better way to do this, and maybe in a seperated Task to stop UI freeze??
,然后使用循环将Add项目添加到Items集合,最后调用 EndUpdate :Which is equivalent to using below code. First call BeginUpdate method of ListBox and then use a loop to Add items to Items collection and at last call EndUpdate:
this.listBox1.BeginUpdate(); foreach (var item in array) { this.listBox1.Items.Add(item); } this.listBox1.EndUpdate();Take a look at source code of AddRange method.
这篇关于在另一个线程上使用IEnumrable填充ListBox(winforms)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!