VB.NET 将项目放入列表框后删除组合框中的项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18865403/
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 15:07:03  来源:igfitidea点击:

VB.NET Remove Item in ComboBox after placing in ListBox

vb.netcomboboxlistbox

提问by Sishan

How can I remove item in comboBox after I choose it and put into listBox.

选择组合框中的项目并将其放入列表框后,如何删除该项目。

Here's my code. Please help me.

这是我的代码。请帮我。

Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class frmAdvancePayment


    Private Sub frmAdvancePayment_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lstBillNum.Items.Clear()
        Dim connection_string As String = "Data Source=.\sqlexpress;Initial Catalog=CreditAndCollection;Integrated Security=True"
        Dim connection As New SqlConnection(connection_string)
        connection.Open()
        Dim sql As String = "select BillNum from tblBillingSched where Status ='Unpaid'"
        Dim da As New SqlDataAdapter(sql, connection_string)
        Dim dt As New DataTable
        da.Fill(dt)
        cmbBillNum.DataSource = dt
        cmbBillNum.DisplayMember = "BillNum"
        cmbBillNum.ValueMember = "BillNum"
        connection.Close()
    End Sub



    Private Sub btnGet_Click(sender As Object, e As EventArgs) Handles btnGet.Click
        lstBillNum.Items.Add(cmbBillNum.SelectedValue)
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        lstBillNum.Items.Clear()
    End Sub

End Class

采纳答案by CheapD AKA Ju

it's what you expect ?

这是你期望的吗?

   Private Sub ComboBox1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
           Dim index As Integer = ComboBox1.SelectedIndex
           ListBox1.Items.Add(ComboBox1.Items(index))
           ComboBox1.Items.RemoveAt(index)
       End Sub