这是:
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;
}
}
总是显示“选择正确的名称”。即使它是从下拉列表中选择的。请任何人都可以建议我!