Clearing a drop down list in C#

喜你入骨 提交于 2019-11-30 22:27:21

问题


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..

   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.


回答1:


try

DropDownList1.Items.Clear(); 

No hidden and clear the Drop Down List.




回答2:


you can do as below

while(cmboPayRate.Items.Count>0)
   cmboPayRate.Items.RemoveAt(0);


来源:https://stackoverflow.com/questions/17519278/clearing-a-drop-down-list-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!