• <small id='lUWmC'></small><noframes id='lUWmC'>

    1. <legend id='lUWmC'><style id='lUWmC'><dir id='lUWmC'><q id='lUWmC'></q></dir></style></legend>

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

        在 C# winform 中将所选项目从一个列表框移动到另一个列表框

        时间:2023-10-07

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

              <tbody id='uOAXM'></tbody>

                <tfoot id='uOAXM'></tfoot>

                <i id='uOAXM'><tr id='uOAXM'><dt id='uOAXM'><q id='uOAXM'><span id='uOAXM'><b id='uOAXM'><form id='uOAXM'><ins id='uOAXM'></ins><ul id='uOAXM'></ul><sub id='uOAXM'></sub></form><legend id='uOAXM'></legend><bdo id='uOAXM'><pre id='uOAXM'><center id='uOAXM'></center></pre></bdo></b><th id='uOAXM'></th></span></q></dt></tr></i><div id='uOAXM'><tfoot id='uOAXM'></tfoot><dl id='uOAXM'><fieldset id='uOAXM'></fieldset></dl></div>
                  <bdo id='uOAXM'></bdo><ul id='uOAXM'></ul>
                  <legend id='uOAXM'><style id='uOAXM'><dir id='uOAXM'><q id='uOAXM'></q></dir></style></legend>
                  本文介绍了在 C# winform 中将所选项目从一个列表框移动到另一个列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将列表框 1 中的选定项目移动到列表框 2,反之亦然.我有两个按钮,>><<.当我选择 listbox1 中的项目然后单击 >> 时,项目应该从 listbox1 移动到 listbox2.

                  I'm trying to move selected items in list box1 to list box2, and vice versa. I have two buttons, >> and <<. When I select items in listbox1 and then click on >> the items should move from listbox1 to listbox2.

                  private void MoveListBoxItems(ListBox source, ListBox destination)
                  {
                      ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
                      foreach (var item in sourceItems)
                      {
                          destination.Items.Add(item);
                      }
                      while (source.SelectedItems.Count > 0)
                      {
                          source.Items.Remove(source.SelectedItems[0]);
                      }
                  }
                  
                  private void button2_Click_1(object sender, EventArgs e)
                  {
                      MoveListBoxItems(listbox , lstActivity);
                  }
                  

                  推荐答案

                  您的代码运行良好.我测试了它.您的问题是我尝试将列表框 1 中的 选定 项移动到列表框 2."

                  your code works fine. i tested it. your question is "I try to move selected item in list box1 to list box2."

                  我认为你的 button2 有问题.删除 button2 和下面的代码

                  i think your button2 has problem.delete button2 and the code below

                  private void button2_Click_1(object sender, EventArgs e)
                  {
                      MoveListBoxItems(listbox , lstActivity);
                  }
                  

                  然后创建其他按钮并创建点击事件.

                  then create other button and create click event.

                  完整来源:

                  private void MoveListBoxItems(ListBox source, ListBox destination)
                  {
                      ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
                      foreach (var item in sourceItems)
                      {
                          destination.Items.Add(item);
                      }
                      while (source.SelectedItems.Count > 0)
                      {
                          source.Items.Remove(source.SelectedItems[0]);
                      }
                  }
                  
                  private void first2second_Click(object sender, EventArgs e)
                  {
                      MoveListBoxItems(FirstListbox, LastListbox);
                  }
                  
                  private void second2first_Click(object sender, EventArgs e)
                  {
                      MoveListBoxItems(LastListbox, FirstListbox);
                  }
                  

                  此代码有效.如果要选择多个项目更改属性SelectionMode = MultiSimple;

                  this code is work. if you want select more than one item change property SelectionMode = MultiSimple;

                  这篇关于在 C# winform 中将所选项目从一个列表框移动到另一个列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:ItemsControl 与其项目源不一致 - WPF Listbox 下一篇:winform中的列表框选定项目

                  相关文章

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

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