Solved

How to clear a list box in VB

Posted on 2007-12-05
5
3,211 Views
Last Modified: 2008-03-10
How do you clear a list box in Visual Basic 2005?

I have a button reset that clears everything but I can't get it to clear the list box? how would I do that?
0
Comment
Question by:ashblynn02
5 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 20411258
Listbox.Clear()

Or ListBox.Items.Clear()

Can't remember which it is off the top of my head but it is one of these two.
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20411299
if you are using vb.net 2005 then listbox.items.clear() is the syntax
0
 

Author Comment

by:ashblynn02
ID: 20411462
neither of those are working.... :(
listbox.clear: Error- 'clear' is not a member of 'System.Windows.Forms.ListBox'.
listbox.items.clear(): Error- Reference to a non-shared member requires an object reference.
 Private Sub Btnreset_enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnreset.Click

        ListBox.Items.clear()

        ListBox.clear()

        txtguess.Text = ""

        listguess.Text = ""

        lblinfo.Text = ""

        btnguess.Enabled = True

        Randomize()

    End Sub

Open in new window

0
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 500 total points
ID: 20411566
Replace change the case of clear() to Clear(), like this

ListBox.Items.Clear()

and remove ListBox.clear()
0
 
LVL 5

Expert Comment

by:23637269
ID: 21087671

  With List1
    .Clear
    .AddItem "Test1"
    .AddItem "Test2"
  End With
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now