Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the data-bound object that populated the row.
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
The data-bound Object.
The following code example demonstrates how to use the DataBoundItem property to access a business object bound to a row. This code example is part of a larger example provided in How to: Access Objects Bound to Windows Forms 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
Accessing data-bound objects directly through row objects is useful when you do not have direct access to the data source containing the objects. It is also convenient when you want to manipulate objects bound to selected rows or to rows passed as arguments to event handlers.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Please sign in to use this experience.
Sign in