mike mcintyre's

.N e t J o u r n a l

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

AprMay 2008Jun
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Archives

Topics

Source Code

Source Code:  Get Data from Double-Clicked DataGridView Row

This article and source code demonstrates how to retrieve the data bound to a Windows Forms DataGridView control row when a user double-clicks a row header.

The approach in this article assumes a scenario where a DataSource has been bound to DataGridView.

The DataGridView control raises the RowHeaderMouseDoubleClick when a user double-clicks a row header. By adding a handler for the RowHeaderMouseDoubleClick event you can add code that retrieves the data behind a row when it is double-clicked:

Code Example

 

Private Sub CustomerDataGridView_RowHeaderMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles CustomerDataGridView.RowHeaderMouseDoubleClick

 

    ' Declare a variable named chosenCustomerRow of type CustomerRow.omerRow

    Dim chosenCustomerRow As AjaxDataSet.CustomerRow

 

    ' Retrieve the CustomerRow object from the DataGridView row;

    ' assign it to the chosenCustomerRow variable.

    chosenCustomerRow = CType(CType(Me.CustomerBindingSource.Current, DataRowView).Row, AjaxDataSet.CustomerRow)

 

    ' Use data from the double-clicked row.

    Dim customerInfo As String = ""

    Dim nl As String = Environment.NewLine

    customerInfo &= "Data retrieved from the row you double-clicked:" & nl & nl

    customerInfo &= chosenCustomerRow.Name & nl

    customerInfo &= chosenCustomerRow.StreetAddress1 & nl

    customerInfo &= chosenCustomerRow.City.Trim & ", " & chosenCustomerRow.State.Trim & "  " & chosenCustomerRow.Zip.Trim & nl

    customerInfo &= "Last Order Date: " & chosenCustomerRow.LastOrderDate

 

    Me.RichTextBox1.Text = customerInfo

 

End Sub

 

For more information visit the links below:

 

DataGridView Class

DataGridView Class Members

BindingSource Class

Click the link above to download Visual Basic source code in a Visual Studio 2005 solution which demonstrates how to retrieve the data bound to a Windows Forms DataGridView control row when a user double-clicks a row header.
 
Mike McIntyre http://www.getdotnetcode.com

 

posted on Friday, November 03, 2006 2:56 PM