Event Handler for DataGridView Rows
I am using a DataGridView control in a Windows form. I have data bound to the view from a structure. I am trying to populate other fields in the form with data in the DataGridView. I use a dataGridView1_RowEnter event handler to extract the data from the CurrentRow. The problem is when I enter a row (by using a down arrow, mouse, etc.) the data extracted from the dataGridView1.CurrentRow.Cells[x].Value.ToString() is from the row I just left rather than the current row that is highlighted with the down arrow or mouse. It appears to move the cursor to the next row, run the code in the handler, and then set the focus on the row (place the right arrow > in the row header). I am looking for an event that fires just after the RowEnter handler to place the code. Any suggestions?
Barry TiptonPosted Feb 25, 2006, 12:21 AM
I know, I'm answering my own question but after experimenting with the DataGridView event handlers I found a solution to this problem. Apparently when the RowEnter event is firing the Current Row is still the provious row. It appears that after the RowEnter event is completed the Current Row is moved to the row and then the CellEnter event is fired. I moved the code to the CellEnter event and it worked well. Hope this help somebody else.