Here is:
Datatable dt;
......
.......
cmbName.DataSource=dt;
cmbName.ValueMember="ID";
cmbName.DisplayMember="Name";
private void cmbName_Validating(object sender, CancelEventArgs e)
{
if (cmbName.Text == string.Empty)
{
MessageBox.Show("select correct name");
e.Cancel = true;
}
else if (cmbName.Items.Contains(cmbName.Text))
{
e.Cancel = false;
}
else
{
MessageBox.Show("select correct name");
e.Cancel = true;
}
}
always shows 'select correct name'. Even it is selected from the dropdownlist. Please Can anybody suggest me!
According to your statement
If you your
cmbname.Textis empty, it shows the Message:When your
cmbname.Textis not empty then again it shows the Message:You have to specify in the else condition what message you want as an output when you select from the
DropDownList.