James Hulse
James Hulse

Reputation: 1581

Can disabling a control cause a radio buttons value to change?

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?

Upvotes: 1

Views: 320

Answers (2)

Han
Han

Reputation: 2037

The problem and solution are explained in more detail here: Dev center forums. This also explains why setting Me.Focus helps fixing the problem.

Upvotes: 2

xpda
xpda

Reputation: 15813

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.

Upvotes: 1

Related Questions