DataGridViewComboBoxColumn:limit MaxDropDownItems [英] DataGridViewComboBoxColumn: limit MaxDropDownItems
本文介绍了DataGridViewComboBoxColumn:limit MaxDropDownItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何限制在 DataGridViewComboBoxColumn
中显示的项目数。
在简单 ComboBox
中,我们可以这样做:
I would like to know how to limit the number of items to show in DataGridViewComboBoxColumn
.
In simple ComboBox
we can do it as:
comboBox1.IntegralHeight = false; //this is necessary to make it work!!!
comboBox1.MaxDropDownItems = 3;
但是如何在 DGV
s comboBox`?
But how to do the same in DGV
s comboBox`?
创建 ComboBoxColumn
时,没有 IntegralHeight
属性。
推荐答案
我想通过我的自己,通过订阅 DataGridViewEditControlShowing
事件,并在其中的这个代码:
I have figured it out by my self, by subscribing toDataGridViewEditControlShowing
event, and with this code inside of it:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.IntegralHeight = false;
cb.MaxDropDownItems = 10;
}
}
现在下拉菜单工作,为 MaxDropDownItems
属性设置的行。
这篇关于DataGridViewComboBoxColumn:limit MaxDropDownItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文