[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Getting value in the first column of the selected row in a datagridview

on the Datagridview, to get the record in the first column of the selected row, i used this in the "cellcontent click" event

 Private Sub GridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles pendingtravelRequestGridView.CellContentClick

Dim Value As String = Me.pendingtravelRequestGridView.Rows(e.RowIndex).Cells(0).Value.ToString()

end sub


when i tried to use the same in the "Double click event" it throws me an error "Row index is not a member of system.eventargs" ...how can iu get the value on the double click event

 Private Sub GridView_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pendingtravelRequestGridView.DoubleClick
0
yuvaratna
Asked:
yuvaratna
  • 2
1 Solution
 
barrislbCommented:
Hi yuvaratna,

I have created a simple solution that might be some help to you. I put a DataViewGrid and a button on a form. I created three columns in my sample and inputed some data in all three columns in runtime mode.  I produce the following code below to answer your question of need. I believe this will solve your problem. In my code below, you could change the 'Celld(0).Value' to whichever column cell you want to use for future development.

 I hope this is some help to your need. :- )

Here's the code:
Private Sub btnGetColCell_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetColCell.Click
        '-- Declare local variables
        Dim RowIndex As Integer = DataGridView.SelectedCells(0).RowIndex
        Dim FirstColCell As String = DataGridView.Rows(RowIndex).Cells(0).Value  '<-- Cells(x) to change col
 
        '-- Display message with the first column cell data.
        MessageBox.Show("Selected data from column 1: " & FirstColCell)
    End Sub

Open in new window

0
 
JackOfPHCommented:
This will do the trick...

Private Sub GridView_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pendingtravelRequestGridView.DoubleClick

If pendingtravelRequestGridView.SelectedRows.count <> 0 then

Dim Value As String = Me.pendingtravelRequestGridView.SelectedRows(0).Cells(0).Value.ToString()

end if

End Sub
0
 
JackOfPHCommented:
or the more appropriate one...

Use the CellContentDoubleClick instead on pendingtravelRequestGridView.DoubleClickEvent

 Private Sub GridView_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles pendingtravelRequestGridView.CellContentDoubleClick

Dim Value As String = Me.pendingtravelRequestGridView.Rows(e.RowIndex).Cells(0).Value.ToString()

    End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now