搜索并从列表框中删除项目 [英] Search and remove item from listbox
本文介绍了搜索并从列表框中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法,以消除从一个列表框基于字符串的项目?
我一直在玩弄了几分钟,这里是我有这么远,但它不工作
的foreach(在LB_upload.Items字符串的文件)
{
ftp.Upload(文件);
INT X = LB_upload.Items.IndexOf(文件);
LB_upload.Items.RemoveAt(X);
}
我可以通过每个项目只循环,但我想要做的东西多一点优雅
解决方案
而(LB_upload.Items.Count大于0)
{
ftp.Upload(LB_upload.Items [0]的ToString());
LB_upload.Items.RemoveAt(0);
}
Is there a way to remove an item from a listbox based on a string?
I have been playing around for a few minutes and here is what i have so far but its not working
foreach(string file in LB_upload.Items)
{
ftp.Upload(file);
int x = LB_upload.Items.IndexOf(file);
LB_upload.Items.RemoveAt(x);
}
I could just loop through each item but I wanted to do something a little more elegant
解决方案
while(LB_upload.Items.Count > 0)
{
ftp.Upload(LB_upload.Items[0].ToString());
LB_upload.Items.RemoveAt(0);
}
这篇关于搜索并从列表框中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文