DataGridView - Focus a specific cell

后端 未结 10 1400
陌清茗
陌清茗 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条回答
  •  -上瘾入骨i
    2020-12-03 01:16

    I had a similar problem. I've hidden some columns and afterwards I tried to select the first row. This didn't really work:

    datagridview1.Rows[0].Selected = true;
    

    So I tried selecting cell[0,0], but it also didn't work, because this cell was not displayed. Now my final solution is working very well:

    datagridview1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;    
    datagridview1.CurrentCell = datagridview1.FirstDisplayedCell;
    

    So this selects the complete first row.

提交回复
热议问题