码迷,mamicode.com
首页 > Windows程序 > 详细

DataGridView的DataGridViewComboBoxColumn列在编辑时自动弹出下拉列表

时间:2014-11-15 12:41:17      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:winform   datagridview   style   blog   http   color   ar   os   sp   

在DataGridView的CellEnter的事件中添加如下代码即可:

if (e.ColumnIndex == dataGridView1.Columns["仓库名"].Index) {
    dataGridView1.BeginEdit(false);
    System.Windows.Forms.ComboBox c = dataGridView1.EditingControl as System.Windows.Forms.ComboBox;
    if (c != null) {
        c.DroppedDown = true;
    }
                
}

 

思路参考来源:https://social.msdn.microsoft.com/Forums/windows/en-US/27b08305-e7ce-4d4d-b608-c544e2748a81/datagridviewcomboboxcell-making-it-drop-down-automatically?forum=winformsdatacontrols

        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) {
            if (dataGridView1.CurrentCell.OwningColumn is DataGridViewComboBoxColumn)
            {
                System.Windows.Forms.ComboBox combo = (System.Windows.Forms.ComboBox)e.Control;
                combo.KeyDown += new KeyEventHandler(combo_KeyDown);
            }
        }

        void combo_KeyDown(object sender, KeyEventArgs e) {
            System.Windows.Forms.ComboBox c = sender as System.Windows.Forms.ComboBox;
            if (c != null) {
                c.DroppedDown = true;
            }
        }

 

DataGridView的DataGridViewComboBoxColumn列在编辑时自动弹出下拉列表

标签:winform   datagridview   style   blog   http   color   ar   os   sp   

原文地址:http://www.cnblogs.com/albert1017/p/4099099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!