日期:2014-05-18  浏览次数:20974 次

datagridview中设置某列为下拉框怎么弄
datagridview中设置某列为下拉框怎么弄

------解决方案--------------------
datagridcomboboxcolumn
?
------解决方案--------------------
探讨

谢谢,那请问在哪里输入下拉框的值呢

------解决方案--------------------
C# code
        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.Columns.Add(new DataGridViewComboBoxColumn());
            
            List<Item> data=new List<Item>();
            for (int i = 0; i < 10; i++)
            {
                Item item = new Item();
                item.str1 = i.ToString();
                item.list.AddRange(new string[] {"sfa","fasa","sfasf" });
                item.str2 = (i + 1).ToString();

                data.Add(item);
                dataGridView1.Rows.Add();
                DataGridViewComboBoxColumn com = (dataGridView1.Columns[0] as DataGridViewComboBoxColumn);
                com.DataSource = item.list;
            }
            //dataGridView1.DataSource=data;
        }
    }
    class Item
    {
         string _str1;
         List<string> _list = new List<string>();
         string _str2;

        public string str1
        {
            get {
                return _str1;
            }
            set {
                _str1 = value;
            }
        }
        public List<string> list
        {
            get
            {
                return _list;
            }
            set
            {
                _list = value;
            }
        }
        public string str2
        {
            get
            {
                return _str2;
            }
            set
            {
                _str2 = value;
            }
        }
    }