Scroll bar in incorrect position - Datagridview

Asked

Viewed 338 times

1

I am trying to select the last line in a Datagridview after including a new item. For this I am running the following code:

dgwVenda.ClearSelection()
dgwVenda.Rows(dgwVenda.Rows.Count - 1).Selected = True
If dgwVenda.Controls(1).Visible = True Then
    dgwVenda.FirstDisplayedScrollingRowIndex = dgwVenda.Rows(dgwVenda.Rows.Count - 1).Index
End If

After the execution the last line is selected and appearing in the Grid, but the scroll bar (vertical) is at the top, when it should be at the bottom. Also the mouse scrolling (by scroll) does not work.

After the position of the bar is changed by a mouse click its function is back to being correct.

Is there any way for the scroll bar to be in the lower position and the scrolling to work by the mouse scroll?

1 answer

1


If the goal is to put the Scroll always positioned on the last line, you can use the following code:

dgwVenda.FirstDisplayedScrollingRowIndex = dgwVenda.RowCount - 1

As to the Scroll of DataGridView not work with the scroll of the mouse, may be due to the fact that the grid loses its focus and thus the possibility to use the Scroll. If so, you can "force" the focus by hovering the mouse on the grid:

Private Sub dgwVenda_MouseEnter(sender As Object, e As EventArgs) Handles dgwVenda.MouseEnter
    dgwVenda.Focus()
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.