代码之家  ›  专栏  ›  技术社区  ›  Tom

如何将焦点设置到datagridview中的新行-运动模拟

  •  5
  • Tom  · 技术社区  · 17 年前

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

    6 回复  |  直到 10 年前
        1
  •  11
  •   phihag    12 年前

    要关注新添加的行,请执行以下操作:-

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

    或者您可以使用它来关注userdefine行

    dataGridView1.Rows(Rowindex).Selected = true;
    

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

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

    继续编码

        2
  •  5
  •   David Rönnqvist    14 年前
    dim NoRow As Integer = 2
    me.gridTickets.CurrentCell = me.gridTickets.Rows(NoRow).Cells(0)
    
        3
  •  3
  •   Kym NT    10 年前
       dgvSimpleReports.Rows(dgvSimpleReports.Rows.Count - 1).Selected = True
       dgvSimpleReports.CurrentCell = dgvSimpleReports.Rows(dgvSimpleReports.Rows.Count - 1).Cells(0)
    

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

        4
  •  2
  •   RichardOD    17 年前

    看看 CurrentCell 财产。

        5
  •  1
  •   sra Jon    14 年前
    If (DgViewCityMaster.Rows.Count > 0) Then
                DgViewCityMaster.Rows(0).Selected = True
            End If
    

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

        6
  •  0
  •   James    17 年前

    您想处理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
    
    推荐文章