>I need a strategy to debug this situation...
>
[quoted text clipped - 79 lines]
>
> -Dan
Hey Robin,
Thanks for the reply. I actually managed to solved the problem, but I
still wonder if there would have been an easier way. Some comments
below.
> So I'd put a breakpoint where you first set
> _parentDataCell. When you get there and it stops,
> right-click on it and add a Watch on it. Then step
> through your code, and watch it in the Watch
> window and see when it changes.
Good idea. Actually what I tried :) But here's the problem: You can
only step through the debugger until all code associated with an event
is run. Then the debugger just stops. It wasn't until several mouse
clicks later that the link was getting lost.
So, I thought: put a break point in click event and keep watching the
value. But there was a problem with that too. The event handlers are in
a different class than _parentDataCell, so _parentDataCell is out of
scope (i.e., you can't see its value in the debugger/watcher).
Also, new instances of the class containing _parentDataCell get created
as the user clicks various buttons, so, how would the watcher know
which _parentDataCell I was talking about anyway?
The only solution I could think of was to create a shared (static)
variable called _firstParentDataCell, and set it equal to
_parentDataCell only if _parentDataCell had not yet been set. Then I
wrote a little shared function that tests to see whether
_firstParentDataCell is still "intact." Finally, I placed calls to the
function strategically through the code to see when the data was
getting lost.
This worked but it sure seemed like a lot of hassle. Turned out, the
bug was caused by one of those user clicks causing the filter on the
original DataGridView to get reapplied. The cell in question was still
there, but the act of refiltering caused all references to go blooey.
So, yeah, programming is hard :)
-Dan
> The easiest thing to do is add the line where you
> set _parentDataCell right before you use it again.
[quoted text clipped - 101 lines]
> >
> > -Dan
RobinS - 14 Nov 2006 22:59 GMT
It's cool that you figured out what the problem was.
You could also have set ParentDataCell as a property,
but that has the same impact as your solution.
If programming wasn't hard, then anybody could do it,
and it wouldn't be fun any more.
Robin S.
-----------------
> Hey Robin,
>
[quoted text clipped - 144 lines]
>> >
>> > -Dan