Meir
Meir

Reputation: 12755

Accessing a object in a datagridview

I followed the simple tutorial here: http://www.codeproject.com/KB/grid/dataGridview-DataReader.aspx to create a datagridview filled with objects.

How do I access the objects in the DGV? I tried (mydgv.CurrentRow.index as Tool).id, but it didn't work.

Any suggestions?

Thanks,

Dave

Upvotes: 2

Views: 119

Answers (2)

SLaks
SLaks

Reputation: 887275

You're looking for the DataBoundItem property:

var row = (Tool)mydgv.CurrentRow.DataBoundItem;

Upvotes: 0

Karel
Karel

Reputation: 2212

You can access them in the ItemDataBound event of the datagridview. You can cast the e.Item.DataItem to you class.

Upvotes: 2

Related Questions