是否可以禁用c#中的下拉列表组合框中的项目? [英] Is it possible to disable an item in a dropdownlist combobox in c#?

查看:1168
本文介绍了是否可以禁用c#中的下拉列表组合框中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以禁用c#中的下拉列表中的项目吗?

Can I disable an item in a dropdownlist in c#?

例如,我有2个dropdownlist组合框。他们都是月份(jan,feb,mar,apr等),两者都将在一定年份内像个月份一样发挥作用。
当我在第一个组合框中选择apr时,第二个组合框不能选择jan,feb,mar

For example, I have 2 dropdownlist combobox. Both of them consist of months (jan, feb, mar, apr, etc....) and both of them will function like a range of month in a certain year. When I choose apr on the 1st combobox, the second combobox can't choose jan, feb, mar

推荐答案

是的,您可以。

您的下拉列表中的ListItem 有一个启用属性。您可以将其设置为 false 以禁用它们。

ListItems in your dropdownlist have an Enabled property. You can set this to false to disable them.

编辑:

对不起,我假设你正在使用WebForms(ASP.Net)。对于Windows窗体,您可以查看以下答案:创建具有非空格的WinForms组合框 - 可选项 - 它的原理相同,但有一些细微的实现细节,因为Combobox 项目集合是一个对象。 Dropdownlist (Web表单等效)使用类型化的ListItem对象。

Sorry I made the assumption you were using WebForms (ASP.Net). For windows forms, you can take a look at this answer: Create WinForms ComboBox with non-selectable items - its the same principle but with some slight implementation details because Combobox Items collection is one of objects. Dropdownlist (the Web form equivalent) uses typed 'ListItem' objects.

HTH。

这篇关于是否可以禁用c#中的下拉列表组合框中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆