Windows Mobile 中ComboBox【下拉列表】的使用
【1】使用xml数据源绑定数据
/// <summary>
/// 从MiddleCateGoryName.xml文件中读出数据添加到(中类别)下拉框中
/// </summary>
private void ReadMiddleCategoryXml()
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
if (File.Exists(strConfigFileUrl + "MiddleCateGoryName.xml"))
{
ds.ReadXml(strConfigFileUrl + "MiddleCateGoryName.xml");
if (ds.Tables.Count < 1)
{
return;
}
dt = ds.Tables[0];
cbxMiddleCategory.Items.Clear();
foreach (DataRow dr in dt.Rows)
{
cbxMiddleCategory.Items.Add(dr["rightName"].ToString());
}
}
}
【2】双击 该控件,获取该选择事件;
private void cbxMiddleCategory_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbxMiddleCategory.Items[Convert.ToInt32(cbxMiddleCategory.SelectedIndex)].ToString() != null)
{
string strCategoryName = cbxMiddleCategory.Items[Convert.ToInt32(cbxMiddleCategory.SelectedIndex)].ToString(); //获取选择的值
}
}