gpt4 book ai didi

c# - DataGridViewComboBoxColumn : limit MaxDropDownItems

转载 作者:太空宇宙 更新时间:2023-11-03 10:46:31 29 4
gpt4 key购买 nike

我想知道如何限制在 DataGridViewComboBoxColumn 中显示的项目数。在简单的 ComboBox 中,我们可以这样做:

comboBox1.IntegralHeight = false; //this is necessary to make it work!!!
comboBox1.MaxDropDownItems = 3;

但是如何在 DGV 的 comboBox` 中做同样的事情呢?

创建 ComboBoxColumn 时没有 IntegralHeight 属性。

最佳答案

我自己想通了,通过订阅 DataGridViewEditControlShowing 事件,并在其中包含以下代码:

private void dataGridView1_EditingControlShowing(
object sender,
DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.IntegralHeight = false;
cb.MaxDropDownItems = 10;
}
}

现在下拉菜单可以工作了,它显示的行数与为 MaxDropDownItems 属性设置的一样多。

对于 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

关于c# - DataGridViewComboBoxColumn : limit MaxDropDownItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155293/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com