ListBox Clear...

JaedenRuiner

Registered User.
Local time
Today, 13:29
Joined
Jun 22, 2005
Messages
154
Is there a way to Clear all the items from a value list listbox.
Basically I'm adding items to a listbox via command buttons, and when I close the form I run some processes based upon those values. But after I process the items I want to clear the list. Is there a way to do this other than manuall removing each item?

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
JaedenRuiner said:
Is there a way to Clear all the items from a value list listbox.
Basically I'm adding items to a listbox via command buttons, and when I close the form I run some processes based upon those values. But after I process the items I want to clear the list. Is there a way to do this other than manuall removing each item?

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner


Im in the process of doing the same thing, how are you adding the items to the list box via command buttons.

Are you moving it from one list box to another or how are you doin it?
 
seanog2001 said:
Im in the process of doing the same thing, how are you adding the items to the list box via command buttons.

Are you moving it from one list box to another or how are you doin it?

I have a TextBox and two Buttons, "Add" and "Delete"

Add_Click()
Code:
  Dim sID As String, _
      vTitle As Variant
    
    sID = TextEdit.Value
    If IsNumeric(sID) And (Len(sID) = 8) Then
      vTitle = DLookup("[title]", Table_Inventory, "[Item_id] = '" & sID & "'")
      If Not IsNull(vTitle) Then
        Call ItemList.AddItem(sID & ";" & vTitle)
        ItemEdit.Value = ""
      Else
        MsgBox "ID: """ & sID & """ not found in Inventory.", vbOKOnly, "Invalid Item ID"
      End If
      ItemText.SetFocus
    End If

At the close of the add event, if the item was added i clear the textbox. And no matter what then Return the focus to the textbox for the next item to be added. (thus the user can use the alt+a quick-key for the add button)

Delete_Click()
Code:
  Dim vItem As Variant, _
      sStr As String, _
      I As Integer, _
      iCnt As Integer, _
      vList As Variant
    
    iCnt = ItemList.ItemsSelected.Count
    If iCnt > 0 Then
      Call ReallocArr(vList, iCnt)
      For I = 0 To iCnt - 1
        vList(I) = ItemList.ItemsSelected(I)
        sStr = sStr & Space(3) & vList(I) & ": " & ItemList.Column(0, vList(I)) & vbTab & ItemList.Column(1, vList(I)) & vbCrLf
      Next I
      If MsgBox("Remove items: " & vbCrLf & sStr & "From List?", vbYesNo, "Remove Tape IDs") = vbYes Then
        For I = iCnt - 1 To 0 Step -1
          Call ItemList.RemoveItem(vList(I))
        Next I
      End If
    End If

This sets up an array of all the items that are selected in the multi-select list, so that the user can delete items from the list manually as necessary. I cycle backwards through the array of indicies, so to avoid index changes when index 2 is deleted index 4 becomes 3, etc.

However, when the form opens I want to clear the list, so the user enters fresh data each time.

thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
Easy enough to clear everything

Just set the rowsource property of the listbox to "". ie me.lstList.rowsource = ""
 

Users who are viewing this thread

Back
Top Bottom