drx_072 drx_072 - 19 days ago 5
Vb.net Question

index statement code | ms-access and vb.net

i have problem with my code (ms-access and vb.net) :
i want to use this code :

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Try
Dim indx As Integer = Convert.ToInt32(DataGridView1(1,e.RowIndex).Value)


in this case :

Private Sub FlatButton4_Click(sender As Object, e As EventArgs) Handles FlatButton4.Click
Try
Dim indx As Integer = Convert.ToInt32(DataGridView1(1,e.RowIndex).Value)


but i have a error in : [e.RowIndex]

how to resolve it ?

Answer

As you can see, in the Click event handler of your button, e is type EventArgs while in the CellClick event handler of the DataGridView it is type DataGridViewCellEventArgs. It makes sense that RowIndex would be a member of that second type, which is specific to a DataGridView, while not of the first type, which knows nothing about the grid.

If what you want is to access a cell in the currently selected row then use this:

Dim indx As Integer = Convert.ToInt32(DataGridView1.CurrentRow.Cells(1).Value)