DataGrid - using ArrayList as DataSource

  • Thread starter Thread starter Mark
  • Start date Start date
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
 
The CurrencyManager.Current property should return
the actual object.

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

/claes
 
Back
Top