DataGridViewComboBoxColumn:限制 MaxDropDownItems [英] DataGridViewComboBoxColumn: limit MaxDropDownItems
本文介绍了DataGridViewComboBoxColumn:限制 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
的comboBox`中做同样的事情?
But how to do the same in DGV
s comboBox`?
创建ComboBoxColumn
时没有IntegralHeight
属性.
推荐答案
我自己弄明白了,通过订阅 DataGridViewEditControlShowing
事件,并在其中包含以下代码:
I have figured it out by my self, by subscribing to DataGridViewEditControlShowing
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
属性设置的行数.
Now the dropdown menu works, it shows as many rows as set for the MaxDropDownItems
property.
对于 Visual Basic
For Visual Basic
Private Sub dgvDesp_EditingControlShowing( _
sender As Object, _
e As DataGridViewEditingControlShowingEventArgs) Handles dgvDesp.EditingControlShowing
Dim cb As ComboBox = e.Control
If cb.Items.Count > 0 Then
cb.IntegralHeight = False
cb.MaxDropDownItems = 10
End If
End Sub
这篇关于DataGridViewComboBoxColumn:限制 MaxDropDownItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文