Reputation: 466
I have binded a BindingList
to a DataGridView
. What I'm trying to do now is changing the underlying item of the BindingList represented in a DataGridView row.
So what I'm trying to achieve is to find a list item of the BindingList
by the corresponding DataGridView row index in order to change that specific item in the BindingList
and ultimately the corresponding DataGridView
row.
Upvotes: 1
Views: 1836
Reputation: 205559
You can use DataGridViewRow.DataBoundItem Property to get reference to the source object bound to a specific DataGridViewRow
. Since you have binded the BindingList
to the DataGridView
, the object returned will originate from that list. Something like this
DataGridViewRow row = ...;
var sourceObject = (YourObjectType)row.DataBoundItem;
// do something with the object
Another way is to use DataGridViewRow.Index Property in combination with your binding list like this:
DataGridViewRow row = ...;
var sourceObject = yourBindingList[row.Index];
// do something with the object
Upvotes: 1