Problem Creating Handle

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a UserControl that contains a few ComboBoxes and TextBoxes. For most
of the Controls/Forms that I drop this on, I'm not having any problems at
all. One form, however, is giving me problems and it seems to be crashing in
the CreateHandle method. I have put a breakpoint in the HandleCreated event
of my UserControl, but it's never hitting it cuz it crashes before that. It's
obviously having a problem creating the handle and I'm trying to figure out
why.

Does anybody know what event fires prior to the HandleCreated event? If I
can set a breakpoint there maybe I can figure out what the problem is.

TIA,
~~Bonnie
 
Well, I figured out the problem, in case any one is interested. It's hard to
debug when you have to know which event is firing in order to set a
breakpoint on it (or on any methods it might call).

I thought I had set breakpoints on all the possible events, but as it turns
out, I didn't. The only thing wrong with my UserControl was that it wasn't
checking whether a few things were null prior to using them. Normally, those
things would not have been null when that method was called (it was a custom
Rebind() method). Even when the UserControl was not data-bound I hadn't had
the problem before. What caused it to be called prematurely on this
particular Form was a SelectedIndexChanged event on a ListView on another
control on the form ... that SelectedIndexChanged event handler executes an
Unbind and Rebind method on it's container (it's parent) ... which basically
does it for all control on the form that implement a custom binding
Interface. My forms that were working correctly didn't happen to call the
Rebind() method and so they worked fine.

Would have been nice to have had a "null reference" exception instead of a
"error creating window handle" error, but oh well.

~~Bonnie
 
Back
Top