1
votes

I have a problem when removing entrys from a BindingList in connection with a DataGridView Here some informations first:

I have a class

public class DeliveryTimeList<T> : IEnumerable<T>, IDeliveryTimeObject where T : IDeliveryTimeData

which implements this interface

public interface IDeliveryTimeObject : IListSource

I use this DeliveryTimeList in a DataGridView.

My class contains a List with visible objects

private List<T> _visibleList;

Because i implement the IListSource i have this Method

public IList GetList()
{
    BindingList<T> blt = new BindingList<T>(_visibleList);
    return blt;
}

When now removing an entry from my _visibleList i get a System.IndexOutOfRangeException. I can't figure out why this is happening. Shouldn't the BindingList handle this ?

2

2 Answers

1
votes

If you try to use the RemoveAt(int index) method of your BindingList make sure that index >= 0 && index < blt.Count otherwise it will throw that exception.

0
votes

I found the answer myself. The _visibleList should have been a BindingList.

So that would result in the following Code

private BindingList<T> _visibleList;

And then simply return it.

public IList GetList()
{
    return _visibleList;
}