如何从列表框中删除文本 [英] How to remove text from a list box

查看:67
本文介绍了如何从列表框中删除文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Basic中制作一个允许用户键入文本并将其添加到列表以及从列表中删除项目的应用程序.到目前为止,我的问题是我无法删除这些项目,我可以添加它们,而不能删除它们.我的代码如下:

I am trying to make an app in Visual Basic that allows an user to type in text and add it to the list as well as remove items from the list. My problem so far is that I can't remove the items, I can add them, just not remove them. My code is as follows:

Public Class Form1
Public Listed As String
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)                        Handles btnAdd.Click
    Dim Prompt As String = "Enter Items To Add Here"
    Listed = InputBox(Prompt) 'Listed is the text from the input box
    lstBox.Items.Add(Listed).ToString() 'lstBox is ListBox1


End Sub

Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)             Handles btnRemove.Click
    With lstBox
        .SelectedItem.Remove(Listed)
    End With
End Sub
End Class

推荐答案

ListBox项没有Remove方法.您应该使用ListBox的Items集合的Remove方法.

ListBox items do not have a Remove method. You should use the Remove method of the ListBox's Items collection.

lstBox.Items.Remove(lstBox.SelectedItem) ' Removes the currently selected item from lstBox

这篇关于如何从列表框中删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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