DataGridView - Focus a specific cell

后端 未结 10 1446
陌清茗
陌清茗 2020-12-03 00:54

How to set focus on any specified cell in DataGridView? I was expecting a simple way like Focus(rowindex,columnindex) but it is not that easy.

10条回答
  •  无人及你
    2020-12-03 01:03

    You can try this for DataGrid:

    DataGridCellInfo cellInfo = new DataGridCellInfo(myDataGrid.Items[colRow], myDataGrid.Columns[colNum]);
    DataGridCell cellToFocus = (DataGridCell)cellInfo.Column.GetCellContent(cellInfo.Item).Parent;
    ViewControlHelper.SetFocus(cellToFocus, e);
    

提交回复
热议问题