views:

262

answers:

2

I have a usercontrol that contains a FlowLayoutPanel (topdown flow) with a bunch of radiobuttons. The control exposes a CheckedChanged event that fires whenever one of the radiobuttons's check changed.

My form contains the usercontrol and a textbox. I subscribe the usercontrol's CheckedChanged event and depending on which radiobutton gets checked, I either disable the textbox or put a focus inside the textbox.

All this works fine with mouseclick when changing the radiobutton's check state. However, this will hang indefinitely when using the arrow keys. I don't understand why the difference.

The following are steps to reproduce the behavior I'm seeing:

  1. Create a usercontrol and drop a FlowLayoutPanel control and set its FlowDirection = TopDown. Then add two radiobuttons to the FlowLayoutPanel.

  2. Provide an event handler in the usercontrol

    public event EventHandler CheckedChanged
    {
        add { radioButton2.CheckedChanged += value; }
        remove { radioButton2.CheckedChanged -= value; }
    }
    
  3. Create a windows form and drop the above user control. Add a textbox and set Enabled to False. Subscribe to the usercontrol's CheckedChanged event as follows

    private void userControl11_CheckedChanged(object sender, EventArgs e)
    {
        textBox1.Select();
    }
    
  4. Run. Notice that if you use the mouse to click between the radiobuttons, thing works fine; but it will crash if you use the up/down arrow keys.

A: 
public event EventHandler CheckedChanged
{
    add {
         radioButton2.CheckedChanged += value;
        }
    remove {
         radioButton2.CheckedChanged -= value;
        }
}

Hmm, value is uninitialized? Or am I missing something?

Anonymous Cow
A: 

Solution: http://support.microsoft.com/kb/970951

_simon_