My datagrid has two textbox columns and two button column. I was trying that when user clicks on button then adjacent textbox cell will be in edit mode and cursor will be placed there.
My textbox columns are in readonly mode.
So I wrote code in cell enter that
private void dgView_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == 2)
{
DataGridView dgv = (DataGridView)sender;
DataGridViewTextBoxCell textBoxCell = dgv.CurrentCell as DataGridViewTextBoxCell;
if (textBoxCell != null)
{
dgv.BeginEdit(true);
}
}
}
I am not getting error but my objective is not fulfill. Textbox cell is not getting in edit mode and cursor is not being placed on the textbox cell. So please tell me and rectify my code as result when I will click on button then adjacent textbox cell will come in edit mode and cursor will blink there.
Try using the
CellClickevent. You don’t really need to callFocus()just set theCurrentCellandBeginEdit: