How To DataGridView DataBoundItem VB2005
description Article and source code explain how to retrieve the object bound to a DataGridView Row using the DataBoundItem property and Visual Basic 2005.
get resource -> How To DataGridView DataBoundItem VB2005
environment Visual Studio 2005
language Visual Basic 2005
namespace System.Windows.Forms.DataGridView
tags databounditem, data, bound, object,datagridview, visual basic, vb net, visual studio, 2005

This article and source code demonstrate how to bind objects stored in a generic List (Of T) to a DataGridView and how to retrieve an individual object when a row header of the DataGridView is double-clicked. The DataGridView Row's DataBoundItem property is used to retrieve the object that is bound to row.

The DataGridView, new in Visual Basic 2005, provides many new members for displaying and manipulating data. One member, the DataGridView Row's DataBoundItem, makes it each to 'get at' the data behind a DataGridView row. This member is especially useful when working with a data source such as a generic List (Of T) object.

Example Application Screenshot

Source Code Excerpt

 

Private Sub PhotosDataGridView_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles PhotosDataGridView.RowHeaderMouseClick

    ' Use the DataBoundItem property of a DataGridView Row to retrieve

    ' the data object bound to the row.

    Dim selectedPhoto As Photo = CType(Me.PhotosDataGridView.Rows(e.RowIndex).DataBoundItem, Photo)

 

    ' Display the photo title, description, and image.

    Me.TitleLabel.Text = selectedPhoto.Title

    Me.DescriptionLabel.Text = selectedPhoto.Description

    Me.PhotoPictureBox.Image = Image.FromFile(selectedPhoto.PathToPhoto)

End Sub

For more information:

DataGridView Class

DataBoundItem Property

 

mike mcintyre http://www.getdotnetcode.com

 

 

 

 

 

 

 

 

 

 



Copyright © 2001-2007 aZ Software Developers. All rights reserved.

 

.