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

Re: DataGrid - using ArrayList as DataSource by Claes

Claes
Mon Dec 06 02:44:26 CST 2004

The CurrencyManager.Current property should return
the actual object.

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

/claes

"Mark" <field027@idonotlikejunkmail.umn.edu> wrote in message
news:uyCi2Ik2EHA.3376@TK2MSFTNGP12.phx.gbl...
> 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
>
>