C#中如何展开ComboBox控件的下拉框?

2024-12-16 05:25:39
推荐回答(5个)
回答1:

建议使用ListBox
ComboBox在运行状态下鼠标点击可以展开

回答2:

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;
}
}

回答3:

将ComboBox的DropDownStyle设置为DropDown,这样运行时点击才能出来下拉框

回答4:

不知道把DropDownStyle的属性改为Simple符不符合你要求

回答5:

是要设置ITEM值么??