R
Robert Brown
Hi there,
Is it normal for form-based events to fire in "InitializeComponent()". I've
got a "DataGridView" on a form and I set its "CellValueChanged" event using
the forms designer. Ok, VS initializes my event in "InitializeComponent()".
However, "InitializeComponent()" later calls
"ComponentResourceManager.ApplyResources()" which (to my great surprise)
fires my event (which my handler then chokes on since it thinks the window
is already running). Looking at the call stack, the event was fired while
initializing the header text on one of my "DataGridView" columns (from the
resource file). I'm not sure if this particular event should even apply in
this situation but in any case, the form hasn't even been created yet. Is it
therefore normal for some form-based events to be fired while the
constructor is still running. If so then it's potentially dangerous to
define events using the forms designer so we should presumably add them
ourselves in "OnLoad()" typically (or otherwise design all handlers to check
that the window has actually been created which is ugly IMO). Can anyone
elaborate on this situation. Thanks.
Is it normal for form-based events to fire in "InitializeComponent()". I've
got a "DataGridView" on a form and I set its "CellValueChanged" event using
the forms designer. Ok, VS initializes my event in "InitializeComponent()".
However, "InitializeComponent()" later calls
"ComponentResourceManager.ApplyResources()" which (to my great surprise)
fires my event (which my handler then chokes on since it thinks the window
is already running). Looking at the call stack, the event was fired while
initializing the header text on one of my "DataGridView" columns (from the
resource file). I'm not sure if this particular event should even apply in
this situation but in any case, the form hasn't even been created yet. Is it
therefore normal for some form-based events to be fired while the
constructor is still running. If so then it's potentially dangerous to
define events using the forms designer so we should presumably add them
ourselves in "OnLoad()" typically (or otherwise design all handlers to check
that the window has actually been created which is ugly IMO). Can anyone
elaborate on this situation. Thanks.