user2257659
user2257659

Reputation: 1

datagridview row selection; not updating to new selection

Almost completed my first VB.Net program. Works great, with one problem. My datagridview displays info on selection of a row. However, it does not consistently change when user selects a different row. I have been selecting a third row, then going back to second row to get updated info.

here's my code so far. Any suggestions to update upon new selection??

Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    Dim i As Integer
    i = DataGridView1.CurrentRow.Index
    Me.txtCJISCode.Text = DataGridView1.Item(5, i).Value
    Me.txtShortDescript.Text = DataGridView1.Item(10, i).Value
    Me.txtDescription.Text = DataGridView1.Item(23, i).Value

End Sub

Upvotes: 0

Views: 1129

Answers (1)

Luke Marlin
Luke Marlin

Reputation: 1398

Depending on the Selection mode of your datagrid, the CurrentRow might not be the selected one. Since you're doing it with the CellContentClick it would be easier to use the event args :

Replace

i = DataGridView1.CurrentRow.Index

by

i = e.RowIndex

Upvotes: 1

Related Questions