Problem binding a wrapped ArrayList to a DataGrid?

D

David Flajole

Hello,

When I create an ArrayList as follows,

private DataGrid dgLotList;

private ArrayList bidColxn;
bidColxn = new ArrayList();


I have no problem using it like so:

dgLotList.DataSource = null;
dgLotList.Refresh();
dgLotList.DataSource = bidColxn;
dgLotList.Refresh();


However, when I create a BidCollection class to wrap the ArrayList (so I can
add my own conditions for adding, removing and such),

public class BidCollection
{
private ArrayList bids;
bids = new ArrayList();
}


And, try to use it as I did above:

private DataGrid dgLotList;

private BidCollection bidColxn;
bidColxn = new ArrayList();

dgLotList.DataSource = null;
dgLotList.Refresh();
dgLotList.DataSource = bidColxn;
dgLotList.Refresh();


I get the following error:

Complex DataBinding accepts as a data source either an IList or an
IListSource

........ So, why does complex DataBinding accept an ArrayList, but not after
I wrap it in another class?

* I tried to declare the class as > public class BidCollection
:IList

This got rid of the error, but now the grid doesn't list the bids
(even though I verified that they are in the BidCollection).

Thanks, dave
 
C

Claes Bergefall

The documentation clearly states the the DataSource must
be one of the following:

DataTable
DataView
DataSet
DataViewManager
IListSource
IList

Your BidCollection is neither of those. How is the grid
supposed to know that your class has some internal member
of type ArrayList? How is it supposed to access it?

You second attempt (inherit IList) should work though, IF
you implemented the interface correctly

Implement you custom collection instead (by inheriting CollectionBase)
if you want full control over what happens

/claes
 
D

David Flajole

You were right - the problem was in my implementation of IList...I will
probably take your suggestion and inherit CollectionBase in this instance.

Thanks for your help!

dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top