Chris

Chris

  • NA
  • 2
  • 0

Datagridview currentcell jumps to wrong row

Jan 9 2007 9:21 AM
 Code from the main form, what happens here is that when an user enters an articlecode the programm validates the code and tries to find the article in the database.

private void dataGridViewOrder_CellValidating(object sender, DataGridViewCellValidatingEventArgs er)

string celValue = er.FormattedValue.ToString();

{

if (er.ColumnIndex == 0)

{

if (!String.IsNullOrEmpty(celValue))

{

//call the class which searches the article

Boolean found = orderEdit.articleToOrder(celWaarde, true);

 

Eventually if the article exists the article is added to the datagridview row which the cellvalidating event came from. Then the focus is changed to the amount cell with the code below:

Main.dataGridViewOrder.CurrentCell = Main.dataGridViewOrder["Amount", row];

Main.dataGridViewOrder.BeginEdit(true);

 

What happens is that the datagridview jumps to the last blank row (the new row the datagridview paints when you edit the last row) and selects the amount cell in that row instead of the row that was just added. The row variable is the right rownumber but still it jumps to the last row for some reason. I tread about everything i could think about and nothing has helped me, anyone got an idea how to solve this ? It seems to be something with the validating event but i cant trace down what it is.


Answers (2)