DataGridView - Focus a specific cell

后端 未结 10 1449
陌清茗
陌清茗 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:28

                //For me it's the best way to look for the value of a spezific column
                int seekValue = 5;
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    var columnValue = Convert.ToInt32(row.Cells["ColumnName"].Value);
                    if (columnValue == seekValue)
                    {
                        dataGridView1.CurrentCell = row.Cells[0];
                    }
                }
    

提交回复
热议问题