Some times we need to prevent(avoid) the focus on some columns in datagridview,mostly these requirment for ReadOnly columns for that i gave some code for that,here which column is required for prevent the focus those columns are should be ReadOnly and write below code in CellEnter Event in datagridview.
private void dgv_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (dgv.CurrentRow.Cells[e.ColumnIndex].ReadOnly)
{
SendKeys.Send("{tab}");
}
}
See below image:
Here Sl.No and Debit columns are ReadOnly so these two columns are out of focus.
I hope this code will help you.
Read more ►
private void dgv_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (dgv.CurrentRow.Cells[e.ColumnIndex].ReadOnly)
{
SendKeys.Send("{tab}");
}
}
See below image:
Here Sl.No and Debit columns are ReadOnly so these two columns are out of focus.
I hope this code will help you.