vb.net 将项目添加到列表框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34381919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:38:51  来源:igfitidea点击:

adding items to listbox

vb.netlistbox

提问by bod

I'm using vb.net forms

我正在使用 vb.net 表单

I'm trying to add items to a listbox one by one from many comboboxes and textboxes

我正在尝试将许多组合框和文本框中的项目一一添加到列表框

the problem is when i add the second item to the listbox it replace the first one

问题是当我将第二个项目添加到列表框时,它会替换第一个项目

i want the listbox to keep the first item and add a new one

我希望列表框保留第一个项目并添加一个新项目

here is my code

这是我的代码

    Private Sub Button39_Click(sender As Object, e As EventArgs) Handles Button39.Click


    ListBox1.Items.Add(ComboBox1.Text.ToString() &
    " " & ComboBox2.Text.ToString() & "  " & textbox1.Text.ToString())

回答by A.Bahrami Bavani

try with this changes

尝试进行此更改

Private Sub Button39_Click(sender As Object, e As EventArgs) Handles Button39.Click
    ListBox1.Items.Add(ComboBox1.SelectedItem.Text.ToString() & " " & ComboBox2.SelectedItem.Text.ToString() & "  " & textbox1.Text.ToString())