C# 如何在从数据库中选择的组合框中显示选定项
我有一个包含项目的组合框。我想从数据库中获取一个值,并在组合框中将该值显示为所选项。但它也应该显示项目 我尝试使用combobox.selectedvalue。但它不起作用,我该怎么办C# 如何在从数据库中选择的组合框中显示选定项,c#,C#,我有一个包含项目的组合框。我想从数据库中获取一个值,并在组合框中将该值显示为所选项。但它也应该显示项目 我尝试使用combobox.selectedvalue。但它不起作用,我该怎么办 SqlDataAdapter komut = new SqlDataAdapter("select * from Ogrenci where ogr_no= '" + Convert.ToInt32(a) + "' ", baglanti); DataTable dt
SqlDataAdapter komut = new SqlDataAdapter("select * from Ogrenci where ogr_no= '" +
Convert.ToInt32(a) + "' ", baglanti);
DataTable dt = new DataTable();
komut.Fill(dt);
DataRow drw1 = dt.Rows[0];
string ogretim = drw1["ogretim"].ToString();
//comboBox7.SelectedItem = comboBox7.FindString(ogretim);
comboBox7.SelectedValue = ogretim;
试试这个:
comboBox7.Items.FindByValue(ogretim).Selected = true;
不工作不是真正的错误。发生了什么事?上次我检查时,
.SelectedValue
或.SelectedItem
未被破坏。对于您的情况,您正在查找的isError 1'System.Windows.Forms.ListBox.ObjectCollection'不包含'FindByValue'的定义,并且找不到接受'System.Windows.Forms.ListBox.ObjectCollection'类型的第一个参数的扩展方法'FindByValue'(是否缺少using指令或程序集引用?)您使用的是列表框还是组合框?我使用的是windowsformComboBox中的ComboBox。项目对您不可用?