当两个列表框都绑定时,如何将内容从一个列表框移动到另一个列表框? [英] How to move contents from one list box to another when both listboxes are bound?

查看:108
本文介绍了当两个列表框都绑定时,如何将内容从一个列表框移动到另一个列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach (string item in listBoxAvailableStops.Items)
             {
                 if (listBoxSelectedStops.Items.Contains(item) == false)
                 {
                     listBoxSelectedStops.Items.Add(item);
                 }
                 else
                 {
                     MessageBox.Show("These Stops are already selected!");
                 }
             }



这是我的代码,我想将内容从listBoxAvailableStops移至listBoxSelectedStops,但是这两个列表框均已绑定.因此,它将显示一个错误,指示必须首先删除绑定.因此,当两个列表框都绑定时,如何将内容从一个列表框移动到另一个列表框.

谢谢&问候

Sairam Bhat
09483265647



This is my code and I want to move the contents from listBoxAvailableStops to listBoxSelectedStops, but both of these listboxes are bound. So it will show an error indicating that the binding would have to be removed first. So how can we move the content from one listbox to another when both these listboxes are bound.

Thanks & Regards

Sairam Bhat
09483265647

推荐答案



而不是直接添加到列表框中,而是添加到基础数据源.列表框的目的是显示绑定数据,然后将其添加到列表中意味着添加到基础数据源.那么,为什么不直接在数据源上执行此操作,第二个列表框将显示它呢?
Hi,

Instead of adding to the list box directly, add to the underlying data source. The purpose of list box is to display the bound data, then adding to it means adding to the underlying data source. So why don''t do it directly on the data source and the second list box will display it


这篇关于当两个列表框都绑定时,如何将内容从一个列表框移动到另一个列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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