开发者

Is it possible to disable an item in a dropdownlist combobox in c#?

开发者 https://www.devze.com 2023-02-10 08:16 出处:网络
Can I disable an item in a dropdownlist in c#? For example, I have 2 dropdownlist combobox. Both of them consist of months (jan, feb, mar, apr, etc....) and both开发者_高级运维 of them will function

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

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


Yes you can.

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

EDIT:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消