Hi,
Sometimes CellEventArgs for ClickCellButton event contains wrong cell.
In the event I'm extracting data from a cell within the same row as clicked cell, and then refresh the whole grid.
Sometimes (when I click the button again just before it returns to unclicked state - the click event execution takes some time) the retrieved data is from some other row.
Is it me doing something wrong or is it bug in your control?
P.S. This is what i get on my trace (After activate is traced in AfterRowActivate event). Proper value is 91. The value 88 is from 91's parent row:
[2011-02-04 18:22:42] After activate 91
[2011-02-04 18:22:42] Click, id = 91
[2011-02-04 18:22:43] After activate 88
[2011-02-04 18:22:43] After activate 143
[2011-02-04 18:22:43] Click, id = 143
[2011-02-04 18:22:44] After activate 142
[2011-02-04 18:25:06] After activate 91
[2011-02-04 18:25:06] Click, id = 91
[2011-02-04 18:25:07] After activate 88
[2011-02-04 18:25:08] After activate 91
[2011-02-04 18:25:08] Click, id = 91
[2011-02-04 18:25:08] After activate 88
Inqb said: In the event I'm extracting data from a cell within the same row as clicked cell, and then refresh the whole grid.
Yes - the cell is different. So should be the row.
The following code:
e.Cell.Row.GetCellValue("EventTypeID");
returns wrong value.
Let's suppose, that the new Click is generated upon clicking old (before refresh) cell and by the time the main thread begins executing the event, the new grid is loaded. What should happen? Should the e.Cell field contain reference to some random cell from new grid?
Anyway, everything should be fine, as the refreshing is not asynchronous and it's between BeginUpdate() and EndUpdate(). And even if it wasn't, shouldn't the newly rendered row, contain proper references (or are they initialized with some garbage and set to proper values later?)
It sounds like there's some sort of timing issue going on there. But without knowing exactly what you are doing inside the event and without being able to see the problem occur, I can only guess.
Re-binding the grid inside of the ClickCellButton event is probably not a great idea, and using BeginUpdate/EndUpdate will probably make things worse. You are basically destroying the cell and the button while the grid is in the middle of processing a click on that button.This could lead to timing issues because the MouseUp and MouseDown may be getting triggered on different elements.
My advice is - take the code out of the ClickCellButton event and put it into a method. Then call that method from ClickCellButton using BeginInvoke. That way the code won't fire until after the grid has completed processing the event.