Click here to Skip to main content
16,021,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Genius,

I am using the following code to focus to a particular cell in datagridview.
C#
private void dgOrderDetails_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
   if (dgOrderDetails.Columns[e.ColumnIndex].Name.ToString().ToUpper() == "BILLINGMONT")
   {
     dgOrderDetails.Focus();
     dgOrderDetails.CurrentCell = dgOrderDetails[dgOrderDetails.CurrentCell.ColumnIndex + 1, dgOrderDetails.CurrentCell.RowIndex];
   }
}

but my data grid cursor is not binding where i am expecting.Sorry for my English.

Please provide me a solution.
Posted
Updated 29-Apr-16 1:21am
v2

You need to do something like:
C#
dataGridView1.CurrentCell = dataGridView1.Rows[rowindex].Cells[columnindex];

Also see some alternatives:
How-set-focus-cell-datagridview-using-C.aspx[^]
Programmatically-giving-focus-to-particular-cell-in-datagridview[^]
 
Share this answer
 
Comments
Cemal Kazik 25-Mar-15 12:23pm    
cemal
C#
grdUser.CurrentCell = grdUser.Rows[e.RowIndex].Cells[2];
                    grdUser.CurrentCell.Selected = true;
                    e.Cancel = true;
 
Share this answer
 
Comments
CHill60 29-Apr-16 7:39am    
The question over 2 years old and already answered. Your answer adds nothing to what is already here
Refer this link

DataGridView - Focus a specific cell[^]

Regards..:)
 
Share this answer
 
Comments
Member 9817377 2-Sep-13 2:43am    
Hi Genius,

Still i am facing the same problem.Is there any alternative way..:-(
Thanks7872 2-Sep-13 2:44am    
There are many alternative ways suggested already. If it work for others,why not for you? Its not that complicated.

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