views:

69

answers:

1

I have different tabs on my UserControl. Each tab has some controls and button. I want to change AcceptButton on the basis of group of controls I am in.

I can use TextChanged event or Enter event to make a button AcceptButton for Textboxes but I have some Comboboxes too. These combos are auto complete so I can't user Enter event on these, because on Enter these combos should be completed.

Following image can explain my problem more.

alt text

Thanks.

A: 

I would suggest adding a handler to the SelectedIndexChanged event on the tab control and doing something like this:

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
    switch (tabControl1.SelectedIndex)
    {
        case 0:
            AcceptButton = button1;
            break;
        case 1:
            AcceptButton = button2;
            break;
    }
}

This is much more reliable than trying to work out what tab you are on using enter and exit events on the individual controls within the tabs.

MikeD