문제

So I've got the existing code which works just fine when using the BindingList -> BindingSource -> Windows Control approach:

_items.Clear();
foreach (Item item in GetItems())
{
   _items.Add(item);
}

Where _items is module level instance of BindingList.

The above code works as it should, in that the grid control I'm using correctly displays the items after they have been added each time.

However, I'm concerned about performance, specifically, having to iterate over each of the items again. I would much prefer code like this:

_items = new BindingList<Item>(GetItems());

But it's not updating the grid with the new items as did the previously mentioned block of code. What am I missing?

도움이 되었습니까?

해결책

With re-initialization, you are breaking the binding link in between. In case you want to update the grid, you have to reassign the broken link as well.

For example, in case its ItemsSource you are binding to, you need to reset that value:

_items = new BindingList<Item>(GetItems());
grid.ItemsSource = _items;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top