DataGrid - using ArrayList as DataSource

M

Mark

Assume you create an ArrayList containing 10 instances of some class. Let's
say it's a Person class with public properties FirstName and LastName. You
then set a winform DataGrid's DataSource property to be the ArrayList.

A user selects the 6th row in the datagrid. I can find the values of the
cells that have been selected, but what I'd really like it to be able to get
a reference to the Person instance that's been selected in the DataGrid
without iterating through the entire collection looking for a matching
primary key or similar.

Is there a way to do this?

Thanks in advance.

Mark
 
C

Claes Bergefall

The CurrencyManager.Current property should return
the actual object.

You can get the CurrencyManager with the following code:
myGrid.BindingContext(myDataSource, myDataMember)

/claes
 

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