如何将焦点设置到 datagridview 中的新行 - vb.net

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1116404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:17:46  来源:igfitidea点击:

how to set focus to the new row in datagridview - vb.net

vb.netdatagridview

提问by RayDelfin

I don't know how to set focus point always to the new row in DataGridView in the beginning??

我不知道如何在开始时将焦点始终设置为 DataGridView 中的新行?

回答by user350701

To focus on the newly added row :-

关注新添加的行:-

dataGridView1.Rows(dataGridView1.Rows.Count - 1).Selected = true;

or you can use this to focus on userdefine row

或者您可以使用它来关注用户定义的行

dataGridView1.Rows(Rowindex).Selected = true;

Ensure just the last full row is selected by using the following in your init code:

通过在 init 代码中使用以下内容,确保只选择最后一整行:

dataGriView1.MultiSelect = False
dataGriView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect

Keep Coding

保持编码

回答by RayDelfin

dim NoRow As Integer = 2
me.gridTickets.CurrentCell = me.gridTickets.Rows(NoRow).Cells(0)

回答by Red

   dgvSimpleReports.Rows(dgvSimpleReports.Rows.Count - 1).Selected = True
   dgvSimpleReports.CurrentCell = dgvSimpleReports.Rows(dgvSimpleReports.Rows.Count - 1).Cells(0)

Selected is not enough, because selected row only selects the row but DataGridView is not focused automatically. You need to set current row , but current row is ReadOnly, so you need to use current cell, because current cell is not ReadOnly, the code stated below should fix this problem.

Selected 是不够的,因为 selected row 只选择了该行而 DataGridView 不会自动聚焦。您需要设置当前行,但当前行是只读的,所以您需要使用当前单元格,因为当前单元格不是只读的,下面的代码应该可以解决这个问题。

回答by RichardOD

Have a look at the CurrentCellproperty.

查看CurrentCell属性。

回答by the

If (DgViewCityMaster.Rows.Count > 0) Then
            DgViewCityMaster.Rows(0).Selected = True
        End If

' Here DGViewCityMaster is my Data Grid View

' 这里的 DGViewCityMaster 是我的数据网格视图

回答by James

You want to handle the RowsAdded event of your DataGridView and just select the newly added row.

您想要处理 DataGridView 的 RowsAdded 事件,只需选择新添加的行。

Private Sub MyDataGridView_RowsAdded(ByVal sender As Object, ByVal e As DataGridViewRowsAddedEventArgs) Handles MyDataGridView.RowsAdded
     MyDataGridView.Rows(e.RowIndex).Selected = true;
End Sub