1

So basically I am trying to validate my drop down list (combobox) using the Validating event. This works, but calls the focus to my drop down list, not allowing a selection to be made.

Is there any way to get the errorProvider working with dropdownlist

 if (ddlTypeOfPass.SelectedIndex < 1)
            {
                errorProvider1.SetError(ddlTypeOfPass, "Type of Pass is required");
                e.Cancel = true;
                return;
            }
            errorProvider1.SetError(ddlTypeOfPass, "");
    }
Spooks
  • 6,937
  • 11
  • 49
  • 66
  • What does "calls the focus" mean? – Hans Passant Sep 23 '10 at 17:39
  • sorry, the focus is set to my drop down list allowing me to only write text. when trying to pull down from the list it flash the list but sends be back to textmode on the drop down list... if that makes sense – Spooks Sep 23 '10 at 17:47

2 Answers2

0

I thought drop-down lists were self-validating. Are you allowing free-form data entry? Is your 0-th item blank and you want to make sure they changed it? You could remove your blank item and skip validation, but sometimes keeping it blank initially is a requirement.

Beth
  • 9,531
  • 1
  • 24
  • 43
  • well it is self validating, and my 0-th is blank. I wanted the errorProvider to be present, and set the focus to the ddl, but the way i am doing it, the focus gets stuck, not allowing you to select an item from the ddl – Spooks Sep 24 '10 at 12:52
0

I have figured this out, sorry my inital post may not have been helpful. I removed the e.Cancel to allow it to continue run, it sets focus, but does not force the user to stay on that control(which I kind of wanted) but this allows the user to actually set the drop down list.

Spooks
  • 6,937
  • 11
  • 49
  • 66