vb.net - 将项目从 listbox1 移动到 listbox2 并返回 vbnet winform
问题描述
我需要将所选项目从 listbox1 移动到 listbox2 并返回。
为此,我首先从服务器检索数据并用两列(名称和 ID)填充数据表。
接下来,我将数据表绑定到 listbox1,以便将 name 作为显示名称,将 id 作为值。
现在我只想将所选项目从 listbox1 移动到 listbox2(我们称之为篮子)。
这样做时,我希望所有移入 listbox2 的选定项目从 listbox1 中消失。
如果出现错误,我希望能够将所选项目从 listbox2 移回 listbox1。
这样做时,我希望 listbox2 中的选定项目消失并在 listbox1 中再次可用。
完成后,listbox2 中的所有项目都将使用它们的名称和 ID 进行处理。
我希望一切都清楚,并提前感谢您的任何建议或帮助。
解决方案
对我来说,它看起来像这样
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Add(ListBox2.SelectedItem)
ListBox2.Items.Remove(ListBox2.SelectedItem)
End Sub
End Class
在这段代码中,我使用了 2 个列表框,ListBox1 和 ListBox2,并在每个列表框中随机播放所选项目,我编写了第一个按钮将项目从 LB1 移动到 LB2,并使用第二个按钮将所选项目从 LB2 移动到 LB1。如果要在数据库中存储相同的记录,请使用 update 方法进行更新。
推荐阅读
- python - Python Selenium:退出原始功能之外的浏览器实例
- python - Google Clouds Compute Engine VM 实例是否适合运行 selenium 项目?
- javascript - 如何使用 CSP cookie 和 http referer 限制对我的 iframe 小部件的访问
- android - 如何将 Jetpack Compose ConstraintLayout 与 Column 一起使用
- c# - Xamarin Forms 无法将集合视图居中
- mysql - 使用 Rand 的 MySQL 子查询
- git - GitHub Actions 的默认“签出 Git 存储库”作业:它有什么作用?
- r - 如何使用循环更改列表中每个数据集中一个因素的颜色?
- python - 如何更改以列表理解形式呈现的词形还原词的输出?
- java - Kafka Streams 忽略 log4j.properties 文件