How to set focus on a particular row in a datagrid/gridview?

前端 未结 6 1524
清酒与你
清酒与你 2021-01-04 18:07

I have a datagrid/gridview. I\'m populating the grid with 10 rows initially. On a button click every time,I\'m keeping on adding 10 rows to the datagrid/gridview. Now I want

6条回答
  •  迷失自我
    2021-01-04 19:02

    This post has been a god send. I am using VB in Visual Studio 2017 and just needed to go to the bottom of a DATAGRID to allow user to input data. By studying these answers I came up with this solution and thought others might find it useful.

    Private Sub AddBUTTON_Click(sender As Object, e As RoutedEventArgs) Handles 
    AddBUTTON.Click
            ' Go to bottom to allow user to add item in last row
            DataGrid.Focus()
            DataGrid.UnselectAll()
            DataGrid.SelectedIndex = 0
            DataGrid.ScrollIntoView(DataGrid.SelectedItem)
            Dim endofitems As Integer = DataGrid.Items.Count         
            DataGrid.ScrollIntoView(DataGrid.Items.GetItemAt(endofitems - 1))
        End Sub
    

提交回复
热议问题