views:

27

answers:

1

I have a For Each loop going through the controls in a panel disabling them. When the loop reaches one certain grid control and disables it the CheckedChanged event fires for the next control in the loop which is a radio button.

The call stack is as follows:

System.Windows.Forms.dll!System.Windows.Forms.RadioButton.OnCheckedChanged(System.EventArgs e = {System.EventArgs}) + 0x15 bytes    
System.Windows.Forms.dll!System.Windows.Forms.RadioButton.WnProc(Microsoft.AGL.Forms.WM wm = WM_RADIOBUTTON_NOTIFYVALUECHANGED, int wParam = 0, int lParam = 0) + 0x17 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control._InternalWnProc(Microsoft.AGL.Forms.WM wm = WM_RADIOBUTTON_NOTIFYVALUECHANGED, int wParam = 0, int lParam = 0) + 0x9 bytes    
System.Windows.Forms.dll!Microsoft.AGL.Forms.WL.SetEnabled(System.IntPtr hwnThis = 1179753, Microsoft.AGL.Common.BOOL fEnabled = fFalse)    
System.Windows.Forms.dll!System.Windows.Forms.Control._SyncEnabled() + 0x21 bytes   
System.Windows.Forms.dll!System.Windows.Forms.Control.Enabled.set(bool value = false) + 0x61 bytes  

I don't understand how control.Enabled = False can cause the OnCheckedChanged event.

Has anyone run into a similar situation and can maybe shed some light on this?

+1  A: 

Is this happening during the load event? Sometimes RadioButtons fire during form initialization, "By Design" according to Microsoft. If this is the case, you can check in the OnCheckedChanged handler to make sure the form is loaded before you do anything.

xpda
Unfortunately, no. I noticed that it does fire during initialisation when the designer code sets the radio button to the default that was chosen in the designer, but this is quite a bit after.
James Hulse