从列表框2中选择的项目移动到项目到列表框1。 [英] From Listbox2 selected item moves to item to listbox1.

查看:370
本文介绍了从列表框2中选择的项目移动到项目到列表框1。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击Listbox2中的删除按钮时,所选项目将移至listbox1。

我的代码如下;

When I click the remove button from Listbox2 the selected item is moved to listbox1.
My code as follows;

Listbox2.Items.Add(listbox1.SelectedItem);



我尝试了下面的代码。



我想检查两个条件。

1.从listbox1中我添加项目并移动到listbox2并单击删除按钮。要删除的Listbox2项目。



2.当我点击listbox2中选择项目的删除按钮时,从listbox2移动到listbox1。



当我将listbox2项目移除到listbox1时listbox2选中的项目不会被删除。



如何在单个删除按钮中执行上述条件。



请帮帮我。我该怎么办。


I tried the below code it is working.

I would like to check two condition.
1. From listbox1 hen I add item and move to listbox2 and click the remove button.Listbox2 item to be removed.

2. From listbox2 when I click the remove button that selected item from listbox2 move to listbox1.

When I removing the listbox2 item to listbox1 that time listbox2 selected item wont be there to be removed.

How to do the above both condition in single Remove Button.

please help me. how can I do.

推荐答案

这是答案



但你必须忽略例外





this is the answer

but you must ignore the exceptions


try
           {
               listBox2.Items.Add(listBox1.SelectedItem);
               listBox1.Items.Remove(listBox1.SelectedItem);
               listBox1.ClearSelected();
               //

           }
           catch(Exception ee){}
           try
           {
               listBox1.Items.Add(listBox2.SelectedItem);
               listBox2.Items.Remove(listBox2.SelectedItem);
               listBox2.ClearSelected();
           }
           catch(Exception ee){}







如果您对代码有任何疑问,请告诉我




let me know if you have any question with code


这篇关于从列表框2中选择的项目移动到项目到列表框1。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆