Form窗体的Combobox键值对绑定
private
void
TestComboForm_Load(
object
sender, EventArgs e)
{
// 打开时调用加载方法
ss();
}
// 声明ListItem
CommonClass.ComboListItem.ListItem item = null ;
private void comboBox1_SelectedIndexChanged( object sender, EventArgs e)
{
// 读取item中值
MessageBox.Show(((CommonClass.ComboListItem.ListItem)comboBox1.SelectedItem).ID);
}
// 加载数据到comboBox1
public void 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 ;
private void comboBox1_SelectedIndexChanged( object sender, EventArgs e)
{
// 读取item中值
MessageBox.Show(((CommonClass.ComboListItem.ListItem)comboBox1.SelectedItem).ID);
}
// 加载数据到comboBox1
public void 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);
}
}