开发者

Exception problem when rebinding DataViewGrid

开发者 https://www.devze.com 2023-01-07 17:02 出处:网络
I have a List<> that I bind to a DataViewGrid using a Binding source. Like this: private void BindGridView(DataGridView dgv, List<KeyTextPair> list, Func<KeyTextPair, int, bool> predic

I have a List<> that I bind to a DataViewGrid using a Binding source. Like this:

    private void BindGridView(DataGridView dgv, List<KeyTextPair> list, Func<KeyTextPair, int, bool> predicate)
   {
        BindingSource bs = new BindingSource();
        bs.DataSource = list.Where(predicate);
        dgv.DataSource = bs;
    }

I have a collection of such lists, which the us开发者_如何学Pythoner can chose from to display in the DVG. However, upon attempting to change one list for another by rebinding I get the error:

"Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function."

I've looked around for a couple of hours but i still haven't figured out why this is happening.

I'll be very happy if one of you guys can help me.

Thanks.


In second line you need to convert collection to list:

bs.DataSource = list.Where(predicate).ToList();

p.s. If that doesn't solve your problem please post your predicate code

cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号