简体   繁体   English

从文本框中填充列表框,而无需在VB中使用按钮或单击事件

[英]Filling a listbox from a textbox without using a button or click event in VB

I'm not sure if it is possible, but I would like to know if a listbox can be updated by adding or removing text by typing that text into a textbox without using a button event or some type of click event. 我不确定是否可以,但是我想知道是否可以通过在不使用按钮事件或某种点击事件的情况下在文本框中键入文本来添加或删除文本来更新列表框。 I've tried using the text_changed event but it inserts the text as I type so I am unable to type an entire string and then move that into a listbox as a whole string. 我尝试使用text_changed事件,但是它会在键入时插入文本,因此我无法键入整个字符串,然后将其作为整个字符串移动到列表框中。

What I am trying to do is scan a magnetic ID card through a reader and have it insert the data from that card into a listbox and when I scan the same card again, it will remove the data. 我要做的是通过读取器扫描磁性ID卡,并将其从该卡中插入到列表框中,当我再次扫描同一张卡时,它将删除数据。 This is for an employee logging system. 这是用于员工记录系统的。

Thanks. 谢谢。

With the following code, if you type a string in TextBox1 and hit Enter, we check to see if the string already exists in ListBox1 . 使用以下代码,如果您在TextBox1键入一个字符串并按Enter,我们将检查该字符串是否已存在于ListBox1 If so, the string is removed from the ListBox, otherwise it is added. 如果是这样,则从列表框中删除该字符串,否则将其添加。 Then TextBox1 is cleared. 然后,清除TextBox1

Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
    If e.KeyChar = vbCr Then
        If ListBox1.Items.Contains(TextBox1.Text) Then
            ListBox1.Items.Remove(TextBox1.Text)
        Else
            ListBox1.Items.Add(TextBox1.Text)
        End If
        TextBox1.Clear()
        e.Handled = True
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改VB列表框“ onclick”事件上的文本框 - Change textbox on a VB listbox 'onclick' event 如果我在textbox1中键入Delhi-Manali,则在按钮上使用vb.net单击event textbox2.text =“ Delhi”&textbox3.text =“ Manali” - If i type Delhi-Manali in textbox1 then on Button Click event textbox2.text=“Delhi” & textbox3.text=“Manali” using vb.net VB-将多个项目从列表框放到文本框 - VB - Put multiple items from ListBox to textbox vb.net通过拖放和双击将值从列表框添加到文本框 - vb.net add values from listbox to textbox via drag&drop AND via double click 使用按钮单击事件处理程序从另一个函数访问VB.Net中循环的值 - Accessing values from a loop in VB.Net from another function using button click event handler 从asp.net文本框回发取消按钮单击事件 - Postback from asp.net textbox cancels button click event 如何处理 VB.NET 中 ListBox 的 SelectedIndex 和双击事件? - How to Handle SelectedIndex and Double Click event for ListBox in VB.NET? vb2008使用文本框搜索列表框 - vb2008 search through listbox using textbox 文本框焦点-使用VB单击与选项卡 - Textbox Focus - Click versus Tab Using VB Sharepoint 2010 webpart vb.net列表框SelectIndexChanged,然后单击按钮 - Sharepoint 2010 webpart vb.net Listbox SelectIndexChanged and Button click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM