drx_072 drx_072 - 1 year ago 63
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
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
Dim indx As Integer = Convert.ToInt32(DataGridView1(1,e.RowIndex).Value)

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

how to resolve it ?

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download