Namespace:
Assembly:
System.Windows.Forms.dll
获取用于填充行的数据绑定对象。
下面的代码示例演示如何使用 DataBoundItem 属性访问绑定到行的业务对象。 此代码示例是如何:访问绑定到 Windows 窗体 DataGridView 行的对象中提供的一个更大示例的一部分。
void invoiceButton_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in this.dataGridView1.SelectedRows)
{
Customer cust = row.DataBoundItem as Customer;
if (cust != null)
{
cust.SendInvoice();
}
}
}
Remarks
当你不能直接访问包含对象的数据源时,通过行对象直接访问数据绑定对象非常有用。 当您希望操作绑定到选定行或作为参数传递给事件处理程序的行时,这也是非常方便的。