DataGridView - Focus a specific cell

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

    you can set Focus to a specific Cell by setting Selected property to true

    dataGridView1.Rows[rowindex].Cells[columnindex].Selected = true;
    

    to avoid Multiple Selection just set

    dataGridView1.MultiSelect = false;
    
    0 讨论(0)
  • 2020-12-03 01:26

    Just Simple Paste And Pass Gridcolor() any where You want.

    Private Sub Gridcolor()
        With Me.GridListAll
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
            '.DefaultCellStyle.SelectionBackColor = Color.MediumOrchid
        End With
    End Sub
    
    0 讨论(0)
  • 2020-12-03 01:27
    public void M(){ 
      dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
      dataGridView1.CurrentCell.Selected = true; 
      dataGridView1.BeginEdit(true);
    }
    
    0 讨论(0)
  • 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];
                    }
                }
    
    0 讨论(0)
提交回复
热议问题