建议使用ListBox
ComboBox在运行状态下鼠标点击可以展开
SqlConnection sqlConn = new SqlConnection(SystemClass.strJlDcmSystemSqlConnection);//连接数据库
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand("SY_YearInfoSelect", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add("@YearCode", SqlDbType.NVarChar, 50);
sqlCmd.Parameters["@YearCode"].Value = "";
SqlDataAdapter sqlAdr = new SqlDataAdapter(sqlCmd);
DataTable dtYearCode = new DataTable();
sqlAdr.Fill(dtYearCode);
for (int i = 0; i < dtYearCode.Rows.Count; i++)
{
cmboxYearInfo.Items.Add(dtYearCode.Rows[i][0]);
}
string strNowYear = ""; //当前的年号
strNowYear = DateTime.Now.Year.ToString();
for (int i = 0; i < cmboxYearInfo.Items.Count; i++)
{
if (cmboxYearInfo.Items[i].ToString() == strNowYear)
{
//默认选择当前年
cmboxYearInfo.SelectedIndex = Convert.ToInt32(strNowYear);
break;
}
}
将ComboBox的DropDownStyle设置为DropDown,这样运行时点击才能出来下拉框
不知道把DropDownStyle的属性改为Simple符不符合你要求
是要设置ITEM值么??