清除 C# 中的下拉列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17519278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clearing a drop down list in C#
提问by Mateo eMayo
I truly do hate to ask such a crayon-question... I'm trying to clear, not remove a drop down combo list in VSC#. My ddl lets the user choose the payRate of an employee. I've researched everywhere, even here, and everything suggests using..
我真的很讨厌问这样一个蜡笔问题......我试图清除,而不是删除 VSC# 中的下拉组合列表。我的 ddl 允许用户选择员工的 payRate。我到处都在研究,甚至在这里,一切都建议使用..
cmboPayRate.Items.Clear(); .. or
cmboPayRate.SelectedIndex = - 1;
I even threw in
我什至扔进去
cmboPayRate.SelectedItem = -1;
for safe measure. Nothing working. Again, I know this is easy(should be), but not working for me. Any suggestions would be greatly appreciated.
为安全措施。没有任何作用。同样,我知道这很容易(应该是),但对我不起作用。任何建议将不胜感激。
Thanks -Matt.
谢谢 - 马特。
回答by Damith
you can do as below
你可以做如下
while(cmboPayRate.Items.Count>0)
cmboPayRate.Items.RemoveAt(0);
回答by Segan
try
尝试
DropDownList1.Items.Clear();
No hidden and clear the Drop Down List.
没有隐藏和清除下拉列表。

