c#去除组合框的可选条目_验证Excel组合框中的条目

c#去除组合框的可选条目

One of my Excel sample files lets you double-click on a cell that has a data validation list, and a combo box pops up. The combo box has advantages, because you can set the font size, and the number of rows in the drop down list, and the entry autocompletes as you type.

我的Excel示例文件之一使您可以双击具有数据验证列表的单元格,并弹出一个组合框。 组合框有很多优点,因为您可以设置字体大小,下拉列表中的行数以及键入时自动完成的条目。

datavalcombovalid01

However, one of the disadvantages is that the combo box lets you type anything, even if it’s not a valid entry from the data validation list. In the combo box shown below, I was able to type “Cold” as a month name.

但是,缺点之一是组合框允许您键入任何内容,即使它不是数据验证列表中的有效条目也是如此。 在下面显示的组合框中,我能够输入“ Cold”作为月份名称。

datavalcombovalid02

And even though there are several cold months in Canada, there isn’t one that’s officially named “Cold”.

即使加拿大有数个寒冷的月份,也没有一个正式命名为“冷”的月份。

If I tried to enter “Cold” in the worksheet cell where the data validation list is, an error message would appear, and the entry wouldn’t be allowed.

如果我尝试在数据验证列表所在的工作表单元格中输入“冷”,则会出现错误消息,并且不允许该条目。

datavalcombovalid04

设置组合框属性 (Set the Combo Box Properties)

In an ideal world, the combo box would prevent me from entering an invalid item. It has a Match Required property, and I have that set to True.

在理想情况下,组合框会阻止我输入无效的项目。 它具有“必须匹配”属性,而我将其设置为True。

datavalcombovalid09

However, as the Excel Help so helpfully points out, “Not all containers enforce this property.” Unfortunately, the worksheet is one of those non-enforcing containers.

但是,正如Excel帮助所指出的那样:“并非所有容器都强制执行此属性。” 不幸的是,工作表是那些非强制性容器之一。

datavalcombovalid10

更改组合框样式 (Change the Combo Box Style)

Because the MatchRequired property doesn’t work, you can change the Combo Box Style property, to prevent people from typing non-list entries. We’ll select List style, which doesn’t allow freeform typing.

由于MatchRequired属性不起作用,因此可以更改“组合框样式”属性,以防止人们键入非列表项。 我们将选择列表样式,该样式不允许自由格式的键入。

In my sample file, the combo box is only visible when you double-click on a data validation cell. To make a change to the combo box properties, follow these steps:

在我的示例文件中,仅当您双击数据验证单元格时,组合框才可见。 要更改组合框属性,请按照下列步骤操作:

  • Double-click on a data validation cell, to show the combo box.

    双击数据验证单元格,以显示组合框。
    • datavalcombovalid05
    • datavalcombovalid06
    • datavalcombovalid07
  • Close the Properties window, and click the Design Mode command again, to turn that setting off.

    关闭“属性”窗口,然后再次单击“设计模式”命令以关闭该设置。

测试组合框 (Test the Combo Box)

To test the revised combo box

测试修订的组合框

  • Double-click on a data validation cell.

    双击数据验证单元。
  • In the combo box, try to type an invalid entry, such as “Cold”

    在组合框中,尝试键入无效的条目,例如“ Cold”

The entry doesn’t appear, because it’s not in the list. In the screen shot below, you can see the result when I tried typing Cold – it defaulted to January, the first item in the list.

该条目未出现,因为它不在列表中。 在下面的屏幕快照中,当您尝试键入Cold时,您可以看到结果–默认为一月,即列表中的第一项。

datavalcombovalid08

下载样本文件 (Download the Sample File)

To see the data validation combo box, and change its properties,  download the sample file from my Contextures website – Data Validation Combo Box Named Ranges.

若要查看数据验证组合框并更改其属性,请从我的Contextures网站– 名为Ranges的Data Validation Combo Box中下载示例文件。

翻译自: https://contexturesblog.com/archives/2013/03/12/validate-entries-in-excel-combo-box/

c#去除组合框的可选条目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值