string strsql = "SELECT R_Id,R_Name From Basic";
DataSet ReturnDataSet1 = conne.ReturnDataSet(strsql);           
           //显示下拉菜单中
comboBox1.DataSource = ReturnDataSet1.Tables[0];
comboBox1.DisplayMember = "R_Name";
comboBox1.ValueMember = "R_Id";======
r_id r_name
102     ha1
233     ha2
334     hee
....
433     ha22
533     ha672
.....
我怎么让comboBox1默认选择433     ha22comboBox1.SelectedValue=433不行
comboBox1.Items.Count怎么等于0

解决方案 »

  1.   

    比如 你的 433    ha22  纪录是第20个,
    那么 在你Form的构造函数里写 comboBox1.Selectedindex = 19;
      

  2.   

    ComboBox数据源为DataTable时,SelectedValue的类型为DataRowView,只要根据值从DataTable的DefaultView中找到值对应的DataRowView,将其设为SelectedValue就可以了foreach (DataRowView thisDrv in ReturnDataSet1.Tables[0].DefaultView)
    {
        if (thisDrv["R_Id"]=433)
        {
            ComboBox1.SelectedValue=thisDrv;
            Break;
        }
    }