Form窗体的Combobox键值对绑定
Form窗体的Combobox键值对绑定
privatevoid TestComboForm_Load(object sender, EventArgs e)
{
//打开时调用加载方法
ss();
}
//声明ListItem
CommonClass.ComboListItem.ListItem item =null;
privatevoid comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//读取item中值
MessageBox.Show(((CommonClass.ComboListItem.ListItem)comboBox1.SelectedItem).ID);
}
//加载数据到comboBox1
publicvoid ss()
{
for(int ii=0;ii<10;ii++)
{
item =new CommonClass.ComboListItem.ListItem("我是值"+ ii.ToString(), "我是名字"+ ii.ToString());
this.comboBox1.DisplayMember = item.Name;
this.comboBox1.Items.Add(item);
}
}
{
//打开时调用加载方法
ss();
}
//声明ListItem
CommonClass.ComboListItem.ListItem item =null;
privatevoid comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//读取item中值
MessageBox.Show(((CommonClass.ComboListItem.ListItem)comboBox1.SelectedItem).ID);
}
//加载数据到comboBox1
publicvoid ss()
{
for(int ii=0;ii<10;ii++)
{
item =new CommonClass.ComboListItem.ListItem("我是值"+ ii.ToString(), "我是名字"+ ii.ToString());
this.comboBox1.DisplayMember = item.Name;
this.comboBox1.Items.Add(item);
}
}