Selecting a row in DataGridView programmatically

后端 未结 8 2388
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 12:58

How can I select a particular range of rows in a DataGridView programmatically at runtime?

8条回答
  •  没有蜡笔的小新
    2020-12-08 13:22

    In Visual Basic, do this to select a row in a DataGridView; the selected row will appear with a highlighted color but note that the cursor position will not change:

    Grid.Rows(0).Selected = True
    

    Do this change the position of the cursor:

    Grid.CurrentCell = Grid.Rows(0).Cells(0)
    

    Combining the lines above will position the cursor and select a row. This is the standard procedure for focusing and selecting a row in a DataGridView:

    Grid.CurrentCell = Grid.Rows(0).Cells(0)
    Grid.Rows(0).Selected = True
    

提交回复
热议问题