简体   繁体   English

在组合框中显示有限的项目

[英]Displaying limited items in combobox

In my project, I have a combobox and has 60 values in it. 在我的项目中,我有一个组合框,其中有60个值。 When I start running the application, I open the combobox to choose a value, it covers all my form application because it has lots of values in it. 当我开始运行应用程序时,我打开组合框来选择一个值,它涵盖了我的所有表单应用程序,因为它有很多值。 It does not look good visually. 它看起来不太好看。 When I open the combobox to select a value, I want to display only 5 of them and user can select the other 55 item by scrolling down. 当我打开组合框来选择一个值时,我想只显示其中的5个,用户可以通过向下滚动选择另一个55项。 How can I do this in C#? 我怎么能在C#中做到这一点?

You should set the MaxDropDownItems property of combobox to 5 and IntegralHeight = true 您应该将comboboxMaxDropDownItems属性设置为5,并将IntegralHeight = true

When IntegralHeight property is set to true, the control automatically resizes to ensure that an item is not partially displayed. 当IntegralHeight属性设置为true时,控件会自动调整大小以确保不会部分显示项目。 If you want to maintain the original size of the ComboBox based on the space requirements of your form, set this property to false. 如果要根据表单的空间要求维护ComboBox的原始大小,请将此属性设置为false。 If the ComboBox does not contain any items, this property has no effect. 如果ComboBox不包含任何项目,则此属性不起作用。

EDIT: another possibility is to set the dropdownheight directly 编辑:另一种可能性是直接设置下拉高度

comboBox1.DropDownHeight = comboBox1.Font.Height * 5;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM