473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Listbox.clear

sassy2009
Hello All,

i have a listbox control named lstDisplay. I have added items to the list using the additem method. But when i tried clearing the listbox using Clear method i cannot find it. i searched for the listbox control's methods and properties using the object browser but cant find Clear in it. Please help.....Access 2003

Thanks
Sassy2009
Oct 28 '09 #1

✓ answered by ADezii

Just as a sidenote, because of the dynamic Re-Indexing of List Box contents after a RemoveItem has been applied, the following code will always remove all entries in a List Box named [lstTest]:
Expand|Select|Wrap|Line Numbers
  1. Dim intItemsInList As Integer
  2. Dim intCounter As Integer
  3.  
  4. intItemsInList = Me![lstTest].ListCount
  5.  
  6. For intCounter = 0 To intItemsInList - 1
  7.   Me![lstTest].RemoveItem 0
  8. Next

7 65161
MikeTheBike
639 Expert 512MB
Hi

Assumning the list Row Source Type is 'Value List' then perhapse
Expand|Select|Wrap|Line Numbers
  1. lstDisplay.RowSource = ""
??

MTB
Oct 28 '09 #2
NeoPa
32,556 Expert Mod 16PB
MTB is on the button with this one.

The opposite of .AddItem though, is .RemoveItem. This enables you to clear a single item from the ListBox.
Oct 28 '09 #3
ADezii
8,834 Expert 8TB
Just as a sidenote, because of the dynamic Re-Indexing of List Box contents after a RemoveItem has been applied, the following code will always remove all entries in a List Box named [lstTest]:
Expand|Select|Wrap|Line Numbers
  1. Dim intItemsInList As Integer
  2. Dim intCounter As Integer
  3.  
  4. intItemsInList = Me![lstTest].ListCount
  5.  
  6. For intCounter = 0 To intItemsInList - 1
  7.   Me![lstTest].RemoveItem 0
  8. Next
Oct 29 '09 #4
NeoPa
32,556 Expert Mod 16PB
When dealing with a diminishing set (This also applies to rows in Excel where you may delete some within the loop) I always start from the end and work backwards. It makes for easier and more obvious code (not that there is anything wrong with ADezii's code you understand) :
Expand|Select|Wrap|Line Numbers
  1. Dim intX As Integer
  2.  
  3. With Me.lstTest
  4.   For intX = .ListCount - 1 To 0 Step -1
  5.     Call .RemoveItem(intX)
  6.   Next intX
  7. End With
Oct 30 '09 #5
Expand|Select|Wrap|Line Numbers
  1. '''ogawd.
  2.  
  3. While Not Me.theListBox.ListCount = 0
  4.  
  5.     Me.theListBox.RemoveItem (0)
  6.  
  7. Wend
  8.  
  9. '''...seems to work each and every time.
  10.  
May 4 '12 #6
NeoPa
32,556 Expert Mod 16PB
Certainly appropriate code for this question. If the clearing is not dependent on any criteria then repeatedly clearing the first item in the list until it's empty makes sense.

I think we're all overlooking the easy answer to the question though, which was supplied by MTB in post #2 ;-)
May 5 '12 #7
Yes, that's definitely a work of art.
May 7 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: amber | last post by:
Hello I'm keeping this list busy! : Okay, now I'm trying to clear a listbox The way I have it set up, the user can either enter a value into a textbox, then hit a button, and 1 specific record is...
0
by: amber | last post by:
Hello, I'm having problems with a listbox... I have a listbox that is populated when a user presses a button (retrieve). There is a textbox on the form, and if the textbox is left blank, and...
4
by: amber | last post by:
Hello I'm not sure if I should give up trying to find an answer here...or just keep posting my problem.. I'm having problems with a listbox.. I have a listbox that is populated when a user...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
3
by: Angel Blue01 | last post by:
I have a form with a binding navigator that draws from a database via drag-and-drop-created controls. I'm filling a listbox with the results of a query. The listbox contains data related to the...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
1
by: sweetiecakes | last post by:
Hi I have a ListBox which is binded to a dataSet. When I need to refresh this dataSet, it works, but the old entries don't get removed from the listbox. Items.Clear() doesn't work when a...
0
by: Stephen Heather | last post by:
hi, i have 4 list boxes that need to have one row from one list box added to the other, then taking from there list boxes and added to another list box together. for instance member of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.