RE: Get object which DataGridView row is bound to -
04-24-2006
, 10:16 PM
Hi,
Thank you for posting. From your post, my understanding on this issue is:
how to get a reference to the business object bound to the current row in a
DataGridView's RowEnter event. If I'm off base, please feel free to let me
know.
When you bind a business object list to a DataGridView, each row in the
DataGridView is bound to a business object in the list. If you want to get
the reference of the object bound to row i, you could use the following
sentence:
object singleobject = dataGridView1.Rows[i].DataBoundItem;
If you know the type of the singleobject, you could make a type conversion
in the upper sentence.
For example, you can use the following sentences in your DataGridView's
RowEnter event handling method to get the reference of the business object
bound to the current row.
private void dgv_RowEnter(object sender, DataGridViewCellEventArgs e)
{
try
{
// get the reference of the business object bound to the current
row, and convert it to Person_BLL type
Person_BLL personInstance =
(Person_BLL)this.dataGridView1.Rows[e.RowIndex].DataBoundItem;
// add your process on the personInstance here
}
catch (Exception ex)
{
ExceptionHandler.ErrLog(ex);
}
}
Hope this is helpful to you.
If you have any other concerns or need anything else, please don't hesitate
to tell me.
Sincerely,
Linda Liu
Microsoft Online Community Support
================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== == |