首页 > 代码库 > DataGridView的DataGridViewComboBoxColumn列在编辑时自动弹出下拉列表
DataGridView的DataGridViewComboBoxColumn列在编辑时自动弹出下拉列表
在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列在编辑时自动弹出下拉列表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。