<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 上设置多个选定项

        时间:2023-10-07
        <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 上设置多个选定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 C# 中的列表框中插入复选框? 下一篇:(c# + windows forms) 将项目添加到不同类的listBox

                  相关文章

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

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