Csharp/C#教程:DataGridViewComboBoxColumn:限制MaxDropDownItems分享


DataGridViewComboBoxColumn:限制MaxDropDownItems

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

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

但是如何在DGV的comboBox中做同样的DGV

创建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属性设置的行MaxDropDownItems

对于Visual Basic

上述就是C#学习教程:DataGridViewComboBoxColumn:限制MaxDropDownItems分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 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 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/988877.html

(0)
上一篇 2021年12月22日
下一篇 2021年12月22日

精彩推荐