Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, While the users enters into Column_1 or Column_2, I wish to focus to a cell in same row & column_3.
So I tried by the following ways, it's not succeeded...

Thanks for the helps & right directions...

C#
private void myDataGrid1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex == 0 && (e.ColumnIndex == 1 || e.ColumnIndex==2 ))
    {
       myDataGrid1.ClearSelection();
       DataGridViewCell MyCell = myDataGrid1.Rows[myDataGrid1.CurrentCell.RowIndex].Cells[3];
       myDataGrid1.CurrentCell = MyCell;
       myDataGrid1.Rows[myDataGrid1.CurrentCell.RowIndex].Cells[3].Selected = true;
    }
}
Posted

1 solution

I would suspect that you forgot to set appropriate SelectionMode:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionmode%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/3c89df86%28v=vs.110%29.aspx[^].

You would need to use System.Windows.Forms.DataGridViewSelectionMode.CellSelect.

—SA
 
Share this answer
 
Comments
Paramu1973 4-Dec-13 3:10am    
Alex I Added the Selection mode code, But It's giving "Re-Entrant call to a SetCurrentCellAddress Core function", error...
Sergey Alexandrovich Kryukov 4-Dec-13 3:17am    
Who are you talking to..?
—SA
Paramu1973 4-Dec-13 3:45am    
Sergey Alex.., May be I call ur Last Name as Alex...
Sergey Alexandrovich Kryukov 4-Dec-13 9:20am    
None of my names is Alex, on none of its forms. Besides, middle name is only used in combination with first one.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900