<legend id='oKF8Z'><style id='oKF8Z'><dir id='oKF8Z'><q id='oKF8Z'></q></dir></style></legend><tfoot id='oKF8Z'></tfoot>

    <small id='oKF8Z'></small><noframes id='oKF8Z'>

    <i id='oKF8Z'><tr id='oKF8Z'><dt id='oKF8Z'><q id='oKF8Z'><span id='oKF8Z'><b id='oKF8Z'><form id='oKF8Z'><ins id='oKF8Z'></ins><ul id='oKF8Z'></ul><sub id='oKF8Z'></sub></form><legend id='oKF8Z'></legend><bdo id='oKF8Z'><pre id='oKF8Z'><center id='oKF8Z'></center></pre></bdo></b><th id='oKF8Z'></th></span></q></dt></tr></i><div id='oKF8Z'><tfoot id='oKF8Z'></tfoot><dl id='oKF8Z'><fieldset id='oKF8Z'></fieldset></dl></div>
    • <bdo id='oKF8Z'></bdo><ul id='oKF8Z'></ul>

      如何遍历列表框中的项目,然后删除这些项目?

      How do I loop through items in a list box and then remove those item?(如何遍历列表框中的项目,然后删除这些项目?)
    1. <i id='9ydim'><tr id='9ydim'><dt id='9ydim'><q id='9ydim'><span id='9ydim'><b id='9ydim'><form id='9ydim'><ins id='9ydim'></ins><ul id='9ydim'></ul><sub id='9ydim'></sub></form><legend id='9ydim'></legend><bdo id='9ydim'><pre id='9ydim'><center id='9ydim'></center></pre></bdo></b><th id='9ydim'></th></span></q></dt></tr></i><div id='9ydim'><tfoot id='9ydim'></tfoot><dl id='9ydim'><fieldset id='9ydim'></fieldset></dl></div>
        <tbody id='9ydim'></tbody>
      <tfoot id='9ydim'></tfoot>
        • <bdo id='9ydim'></bdo><ul id='9ydim'></ul>

        • <small id='9ydim'></small><noframes id='9ydim'>

        • <legend id='9ydim'><style id='9ydim'><dir id='9ydim'><q id='9ydim'></q></dir></style></legend>

                本文介绍了如何遍历列表框中的项目,然后删除这些项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在尝试遍历列表框然后删除项目时遇到以下错误.

                I'm getting the error below when trying to loop through a listbox and then remove the item.

                此枚举器绑定的列表已被修改.枚举器只能在列表不变的情况下使用.

                List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.

                foreach (string s in listBox1.Items)
                {
                    MessageBox.Show(s);
                    //do stuff with (s);
                    listBox1.Items.Remove(s);
                }
                

                如何删除项目并仍然循环浏览内容?

                How can I remove the item and still loop through the contents?

                推荐答案

                要删除所有项目吗?如果是这样,请先执行 foreach,然后使用 Items.Clear() 将它们全部删除.

                Do you want to remove all items? If so, do the foreach first, then just use Items.Clear() to remove all of them afterwards.

                否则,可能会被索引器向后循环:

                Otherwise, perhaps loop backwards by indexer:

                listBox1.BeginUpdate();
                try {
                  for(int i = listBox1.Items.Count - 1; i >= 0 ; i--) {
                    // do with listBox1.Items[i]
                
                    listBox1.Items.RemoveAt(i);
                  }
                } finally {
                  listBox1.EndUpdate();
                }
                

                这篇关于如何遍历列表框中的项目,然后删除这些项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                Cannot remove items from ListBox(无法从列表框中删除项目)
                Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
              1. <tfoot id='pOWw6'></tfoot>

                  <tbody id='pOWw6'></tbody>
                  <bdo id='pOWw6'></bdo><ul id='pOWw6'></ul>

                      <small id='pOWw6'></small><noframes id='pOWw6'>

                      1. <legend id='pOWw6'><style id='pOWw6'><dir id='pOWw6'><q id='pOWw6'></q></dir></style></legend>
                        <i id='pOWw6'><tr id='pOWw6'><dt id='pOWw6'><q id='pOWw6'><span id='pOWw6'><b id='pOWw6'><form id='pOWw6'><ins id='pOWw6'></ins><ul id='pOWw6'></ul><sub id='pOWw6'></sub></form><legend id='pOWw6'></legend><bdo id='pOWw6'><pre id='pOWw6'><center id='pOWw6'></center></pre></bdo></b><th id='pOWw6'></th></span></q></dt></tr></i><div id='pOWw6'><tfoot id='pOWw6'></tfoot><dl id='pOWw6'><fieldset id='pOWw6'></fieldset></dl></div>