-2

Working in Windows Forms (C#), creating a Wizard, I'd like to require the user to select an option in a combobox before being allowed to click "Next" to the next page in the form.

I thought I saw where to do this in the past, but I cannot find anything now.

Thx for any help...!

J

24601
  • 23
  • 1
  • 4

3 Answers3

3

There are multiple ways of doing this. And different application use their preferred way.

One way to have an empty or 'Select Value' option at the top of the list of your combo box. Then when the user click the 'Next' button, check whether this is the value which is selected. If so, don't allow to go next. Otherwise allow to proceed.

My way is to set 'SelectedValue' property to -1 (means select nothing) and check whether is it -1 when the user press 'Next'. (If any valid value is selected, then this property should have a value higher than -1.)

Madushan
  • 6,977
  • 31
  • 79
  • This is logical but when I try it the "Next" button remains enabled. Could there be another place in the Windows Form settings that the "Next" button properties are overriding this code? – 24601 Jun 14 '12 at 18:40
  • You can disable the button at start using the 'Enabled' property, and use a listener on the combo box's 'SelectedIndexChanged' event and enable the button if the index is higher than -1. – Madushan Jun 15 '12 at 01:14
1

Trigger on the selection changed event for the combo box, and then set the button enabled property:

private void comboBoxSelectionChanged(obj sender, EventArgs e)
{
    nextButton.enabled = true;
}
Tom
  • 1,330
  • 11
  • 21
0

There are many ways you can validate the selection ...or force a selection ...2 off the top of my head:

/* sudo */

(o, e) => {
    if(fooCombo.SelectedIndex == {...}) {
        // show dialog, etc.
    }
}
IAbstract
  • 19,551
  • 15
  • 98
  • 146