Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在从数据库中选择的组合框中显示选定项_C# - Fatal编程技术网

C# 如何在从数据库中选择的组合框中显示选定项

C# 如何在从数据库中选择的组合框中显示选定项,c#,C#,我有一个包含项目的组合框。我想从数据库中获取一个值,并在组合框中将该值显示为所选项。但它也应该显示项目 我尝试使用combobox.selectedvalue。但它不起作用,我该怎么办 SqlDataAdapter komut = new SqlDataAdapter("select * from Ogrenci where ogr_no= '" + Convert.ToInt32(a) + "' ", baglanti); DataTable dt

我有一个包含项目的组合框。我想从数据库中获取一个值,并在组合框中将该值显示为所选项。但它也应该显示项目

我尝试使用combobox.selectedvalue。但它不起作用,我该怎么办

  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。项目对您不可用?