this.comboBox1ComboBoxItem newItem = new ComboBoxItem();
                newItem.Text = "This is Value";
                newItem.Value = "This is Display Test";
                comboBox1.Items.Add(newItem);
添加时,上句出现错误,ComboBoxItem报缺少using指令或程序集引用
如何更改,如何添加?

解决方案 »

  1.   

    ComboBoxItem 根本没有这个类,用ListItem
      

  2.   

       ListItem[] list=new ListItem[100];
                list[0]=new ListItem("text","value");
                list[1] = new ListItem("txt1", "vlaue1");
                comboBox1.Items.Add(list[0]);
                comboBox1.Items.Add(list[1]);
      

  3.   

    有ListItem吗?楼主直接声明一个内存表,把你的项都添加到里面。
    再绑定。
      

  4.   

    创建一个实现IList接口的集合类对象,加入作为ComboBox选项的数据,设置ComboBox的ValueMember和DisplayMember,设置ComboBox的DataSource为该集合对象。
      

  5.   


            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                ComboBoxItem selectItem = (ComboBoxItem)comboBox1.SelectedItem;
                MessageBox.Show("您选择了:" + selectItem.DataValue + "|" + selectItem.DisplayValue);
            }        private void Form1_Load(object sender, EventArgs e)
            {
                comboBox1.DisplayMember = "DisplayValue";
                comboBox1.ValueMember = "DataValue";            for (int i = 1; i < 8; i++)
                {
                    ComboBoxItem a = new ComboBoxItem();
                    a.DisplayValue = "显示数据" + i;
                    a.DataValue = "内部数据" + i;
                    comboBox1.Items.Add(a);
                }
                
            }        public class ComboBoxItem
            {
                String displayValue;
                String dataValue;
                public String DisplayValue
                {
                    set
                    {
                        displayValue = value;
                    }
                    get
                    {
                        return displayValue;
                    }
                }            public String DataValue
                {
                    set
                    {
                        dataValue = value;
                    }
                    get
                    {
                        return dataValue;
                    }
                }
            
            }