i have a datagridview named dataGridView1 and having 5 columns.
I just progrmmed in a way that when I enter the itemcode in 2nd column, the details should be displayed and the Currentcell should be moved to 4th column(The 1st & 5th columns are readonly & value of 1st column generates automatically and not by dataGridView1_dafaultvaluesneed ).
Here is the Code for jumping (or changing) Currentcell.
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int idkey = 0;
if (dataGridView1.CurrentCell != null)
rowindex = dataGridView1.CurrentRow.Index;
if (dataGridView1.CurrentCell.ColumnIndex == 1)
if (int.TryParse(dataGridView1.CurrentRow.Cells[1]. FormattedValue.ToString(), out idkey))
for (int i = 0; i < itemdata.Tables["items"].Rows.Count; i++)
if (dataGridView1.CurrentCell.FormattedValue.ToString() == itemdata.Tables["items"]. Rows[i][1].ToString())
dataGridView1.CurrentRow.Cells[2].Value = itemdata.Tables["items"]. Rows[i][2].ToString();
dataGridView1.CurrentRow.Cells[4].Value = itemdata.Tables["items"]. Rows[i][5].ToString();
dataGridView1.CurrentCell = dataGridView1.Rows[rowindex].Cells[3];
break;
}
} }
The problem is:
when the program is executed, it is working well till the above quoted program. When the 2nd column is edited and an Enter key is pressed, it jumps to 3rd column in the next row.
How could I sustain the currentcell in the same row ?
I have tried this too.....
private void dataGridView1_CellEnter(object sender,DataGridViewCellEventArgs e)
if (e.ColumnIndex == 1)
if (e.RowIndex > rowindex)
But an error occured; It says I am trying to edit or reterent the Currentcell property (something like that).
Could U pls help me in solving this?