Focus on custom Cell when entering a Row in DataGridView
-
Hi I have a DataGridview control. I want that, when user enters in NewRow I fill some cells with default values and Focus on costum cell. But i got an Error : (Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.) And my code :
private void dGridViewWork_RowEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == dGridViewWork.Rows.Count-1) { dGridView.Rows[e.RowIndex].Cells[0].Value = "1001"; dGridView.Rows[e.RowIndex].Cells[4].Value = true; dGridView.CurrentCell = dGridViewWork[1, e.RowIndex]; //Error dGridView.BeginEdit(true); } }
An error refers to the line that Focuses on Cell[1,x]. Can you help me? Tanx. -
Hi I have a DataGridview control. I want that, when user enters in NewRow I fill some cells with default values and Focus on costum cell. But i got an Error : (Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.) And my code :
private void dGridViewWork_RowEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == dGridViewWork.Rows.Count-1) { dGridView.Rows[e.RowIndex].Cells[0].Value = "1001"; dGridView.Rows[e.RowIndex].Cells[4].Value = true; dGridView.CurrentCell = dGridViewWork[1, e.RowIndex]; //Error dGridView.BeginEdit(true); } }
An error refers to the line that Focuses on Cell[1,x]. Can you help me? Tanx.I did not get what you meant by that exactly. Still assuming that you are trying to access the row 1. By default you can access only the 1st (0th row). i u want to access, you need to add more rows. else you will get error when you refer to the first row, or any cell from that row, i.e. Cell[1,x]. Still please tell me more about it.
Keshav Kamat :) India
-
I did not get what you meant by that exactly. Still assuming that you are trying to access the row 1. By default you can access only the 1st (0th row). i u want to access, you need to add more rows. else you will get error when you refer to the first row, or any cell from that row, i.e. Cell[1,x]. Still please tell me more about it.
Keshav Kamat :) India
Hi and Tanx Dear friend Cell[1,x] means Cell[ColumnIndex,RowIndex]. I know it's funny but when we want to set CurrentCell we first type columnindex. For example imagine we are at Row number 6 (Last Row) and user press Enter key. DataGridView create new blank row, Now i want to set First Cell's value to 7 programmatically and automatically move cursor to Second cell, then goto input mode . But there is an Error in focussing to second cell in 'RowEnter Event'. Please Help.