我正在开发一个 winforms 应用程序,我有一个从数据库绑定的组合框,每个项目都有一个名称和一个值:
//New item class
public class themeS
{
public string Name { get; set; }
public string Value { get; set; }
public override string ToString() { return this.Name; }
}
//Binding ComboBox Event
using (DbEntities db = new DbEntities())
{
comboBox2.Items.Clear();
IEnumerable tem = from t in db.Themes where t.idCategorie == 1 select t;
foreach (Themes Tem in tem)
{
comboBox2.Items.Add(new themeS { Value = Tem.idTheme.ToString(), Name= Tem.nomTheme });
}
}
现在我想检索组合框选定项的值:
string curentIdTem = comboBox2.SelectedValue.ToString();
的返回值comboBox2.SelectedValue
始终为 'NULL' ,有人可以帮我吗?