<legend id='1cuRg'><style id='1cuRg'><dir id='1cuRg'><q id='1cuRg'></q></dir></style></legend>
  • <small id='1cuRg'></small><noframes id='1cuRg'>

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

        如何在 WinForms ListBox 上设置多个选定项

        How to set multiple selected items on a WinForms ListBox(如何在 WinForms ListBox 上设置多个选定项)
        <tfoot id='3qwSb'></tfoot>
          <tbody id='3qwSb'></tbody>
          <bdo id='3qwSb'></bdo><ul id='3qwSb'></ul>
          <i id='3qwSb'><tr id='3qwSb'><dt id='3qwSb'><q id='3qwSb'><span id='3qwSb'><b id='3qwSb'><form id='3qwSb'><ins id='3qwSb'></ins><ul id='3qwSb'></ul><sub id='3qwSb'></sub></form><legend id='3qwSb'></legend><bdo id='3qwSb'><pre id='3qwSb'><center id='3qwSb'></center></pre></bdo></b><th id='3qwSb'></th></span></q></dt></tr></i><div id='3qwSb'><tfoot id='3qwSb'></tfoot><dl id='3qwSb'><fieldset id='3qwSb'></fieldset></dl></div>
          <legend id='3qwSb'><style id='3qwSb'><dir id='3qwSb'><q id='3qwSb'></q></dir></style></legend>

              • <small id='3qwSb'></small><noframes id='3qwSb'>

                • 本文介绍了如何在 WinForms ListBox 上设置多个选定项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个处于多选模式的 System.Windows.Forms.ListBox 和一组我想被选中的项目.我该怎么做?

                  I have a System.Windows.Forms.ListBox in multiple selection mode and a set of items I'd like to be selected. How do I do that?

                  [Test]
                  public void SetListBox()
                  {
                      var listBox = new ListBox();
                      var items = new List<string>{"one", "two", "three", "four"};
                      listBox.SelectionMode = SelectionMode.MultiSimple;
                      listBox.Items.AddRange(items.ToArray());
                      var selectedItems = new List<string> {"two", "four"};
                      // ???
                      Assert.AreEqual(selectedItems, listBox.SelectedItems);
                  }
                  

                  推荐答案

                  这样做:

                  selectedItems.Select(sd => listBox.Items.IndexOf(sd)).Where(i => i >= 0).ToList().ForEach(i => listBox.SetSelected(i, true));
                  

                  为:

                      [Test]
                      public void SetListBox()
                      {
                          var listBox = new ListBox();
                          var items = new List<string>{"one", "two", "three", "four"};
                          listBox.SelectionMode = SelectionMode.MultiSimple;
                          listBox.Items.AddRange(items.ToArray());
                  
                          var selectedItems = new List<string> {"two", "four"};
                          selectedItems.Select(sd => listBox.Items.IndexOf(sd)).Where(i => i >= 0).ToList().ForEach(i => listBox.SetSelected(i, true));
                  
                          Assert.AreEqual(selectedItems, listBox.SelectedItems);
                      }
                  

                  这篇关于如何在 WinForms ListBox 上设置多个选定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 列表框上的取消选择)

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

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

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

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