DataGridViewRow.DataBoundItem 属性

定义

获取用于填充行的数据绑定对象。

public:
 property System::Object ^ DataBoundItem { System::Object ^ get(); };
[System.ComponentModel.Browsable(false)]
public object DataBoundItem { get; }
[System.ComponentModel.Browsable(false)]
public object? DataBoundItem { get; }
[<System.ComponentModel.Browsable(false)>]
member this.DataBoundItem : obj
Public ReadOnly Property DataBoundItem As Object

属性值

绑定了数据的 Object

属性

示例

下面的代码示例演示如何使用 DataBoundItem 属性访问绑定到行的业务对象。 此代码示例是 How to: Access Objects Bound to Windows 窗体 DataGridView Rows 中提供的更大示例的一部分。

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();
        }
    }
}
Private Sub InvoiceButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles InvoiceButton.Click

    For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows

        Dim cust As Customer = TryCast(row.DataBoundItem, Customer)
        If cust IsNot Nothing Then
            cust.SendInvoice()
        End If

    Next

End Sub

注解

如果没有直接访问包含对象的数据源,则通过行对象直接访问数据绑定对象非常有用。 如果要操作绑定到所选行或作为参数传递给事件处理程序的行的对象,也很方便。

适用于

另请参阅