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.
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;
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
public void M(){
dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
dataGridView1.CurrentCell.Selected = true;
dataGridView1.BeginEdit(true);
}
//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];
}
}