DataGridViewComboBox:DropDownWidth错误 [英] DataGridViewComboBox : DropDownWidth Error

查看:63
本文介绍了DataGridViewComboBox:DropDownWidth错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

 // Set DataGridView comboBox Date for Non-Rec
            DataGridViewComboBoxColumn comboBoxDate = getComboBoxDate();
            comboBoxDate.DropDownWidth = 6;
            dataGridViewNon_Rec.Columns.Add(comboBoxDate);

private DataGridViewComboBoxColumn getComboBoxDate()
        {
            DataGridViewComboBoxColumn comboBoxDate = new DataGridViewComboBoxColumn();
            comboBoxDate.Items.AddRange(new object[] {
            "01",
            "02",
            "03",
            "04",
            "05",
            "06",
            "07",
            "08",
            "09",
            "10",
            "11",
            "12",
            "13",
            "14",
            "15",
            "16",
            "17",
            "18",
            "19",
            "20",
            "21",
            "22",
            "23",
            "24",
            "25",
            "26",
            "27",
            "28",
            "29",
            "30",
            "31"});

            comboBoxDate.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
            comboBoxDate.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;

            return comboBoxDate;
        }

即使将DataGridViewComboBox的Drop Down Width设置为6,我仍然看到列出的所有30个项目.可能是什么问题?

Even after I set the Drop Down Width of the DataGridViewComboBox to 6, I see all the 30 items listed. What could be the problem?

推荐答案

使用MaxDropDownItems属性选择要在列表中显示多少项:

Use MaxDropDownItems property to choose how many items to show in the list at ones:

        public Form1()
        {
            InitializeComponent();
            dataGridView1.Columns.Add("c1", "column 1");
            dataGridView1.Rows.Add("1");
            dataGridView1.Rows.Add("2");
            dataGridView1.Rows.Add("3");
            dataGridView1.Rows.Add("4");
            DataGridViewComboBoxColumn combo = DGV_ComboBox();
            dataGridView1.Columns.Add(combo);
        }

        private DataGridViewComboBoxColumn DGV_ComboBox()
        {
            DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
            {
                combo.Name = "dgvComboBox1";
                combo.HeaderText = "Selection";
                combo.Items.AddRange(new string[] { "01", "02", "03", "04", "05" });
                combo.MaxDropDownItems = 5;
            }
            return combo;
        }


这篇关于DataGridViewComboBox:DropDownWidth错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆