Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Remove Items From 2 Lists


Hi, this forum has proved successful for me in the past so I thought Id give it a go.

I need help with code that will remove items from 2 lists.

For example when somebody clicks in the 1st item of List1 then clicks delete the 1st item in List1 and List2 will be deleted. If they click the 2nd item is List2 then click delete the 2nd item in List1 and List2 will be removed.

Please Help!




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Selecting Items In Lists
what i am trying to do is to have a list of items that correspond to a fields in a database. i can get the list box to display the fields fine but i am struggling to get the next part working

what u want to do is to let the user select an item from the list and then the corresponding record in the database is shown in labels in the form

any help would be grateful as i am really stuck at the mo!

thanks

nige

Lists And Getting Rid Of Multiple Items
Hi,

Is there any way to remove multiple items for a list. For example, the list:

A
H
A
A
K

Is there any way I could just turn it into:

A
H
K

...and remove the extra A's. Thanks.

Selecting Items From 2 Lists, In One List?
ok, is it possible so that when i select the first item in my first list, it will select the first item in my second list aswell? if so, what would the code be, and where would i put it?

How Do I Compare Two Lists To See If Any Items Match? [SOLVED, Thank You]
I have two listboxes. How would I go around comparing their list items to see if they match?

I want to do the following:

If any items from ListView1 matches any items from ListView2, do nothing. Otherwise, display a message box stating that no items from ListView1 were found in ListView2.

Remove Items
Is there a way that when I enter things into a ListBox and by mistake I enter one wrong can I remove it by typing in, in another TextBox the thing I just entered and hitting a CommandButton that will remove what was entered into the TextBox?

Or do you know of an easier way to remove an Item from a list of items in a ListBox?

Thanks

How To Remove Items From App Log File ?
Hello all,

I am using the App Loging feature to create a log file for logging events in my program. Everything is working fine except it's logging some additional stuff that I do not want nor have asked for;

Here's My Simple Code....
________________________________________________________________
Private Sub Form_Load()

Dim MyTime = Now()

' Sets App Event log path. Arg.2 forces logging to this path & File

App.StartLogging "E:Log.Txt", 2

'Log event writes MyTime & Message to E:Log.text. Required 2nd Arg. 4 specifies it's information

App.LogEvent MyTime & " Program Started", 4 '
'
End Sub
__________________________________________________________________


And Here's what the output looks like in my "Log.Txt" file.....

Information Application E:Log.Txt: Thread ID: 2100 ,Logged: 3/11/2005 6:01:44 PM Program Started


Here's What I want......

3/11/2005 6:01:44 PM Program Started


But I am willing to settle for this......

3/11/2005 6:01:44 PM Program Started :Information Application E:Log.Txt: Thread ID: 2100 ,Logged


Any Ideas or Suggestions?


Thanks.

Remove Listbox Items
Is it possible to remove items from listbox by giving item's name not it's index?
I mean if listbox has items Cat, Dog and Cow then what should I do if I want to remove item Dog, but not knowing what index it has?

List Box (Remove Items)
I have a listbox in which I load mp3's for an mp3 player, i also have a "Remove" button on my form, how would I remove JUST the selected song from the list, and not the entire list?? Thanks again!

How To Remove Items From A ComboBox?
Without knowing the number of items in it?

Thanks,

Guy.

Remove Combo Items
i need to remove items in a combo box that already exist in the list but im not sure how. i thought this code i wrote last night would work, but it doesnt, and i cant figure out why. any ideas?



Code:
For b = 1 To cboRecent.ListCount
'c is the array index
c = b - 1
'd is a value linked to c array index
d = cboRecent.List(c)
'nested for to find a match between d & the other items
For e = 1 To cboRecent.ListCount
f = e - 1
If cboRecent.List(f) <> d Then
'add item to list
cboRecent.AddItem (RECENTLIST)
End If
Next e
Next b

Remove Same Items From Two Listboxes!
i wanted to know an effective way to remove same items from two listboxes

for example in the same list box i have


1
2
4
5
6

and in the second
2
3
8
9
0
in this case i wanted 2 to be removed from one of the listbox!

please if u know anything help me!

Remove Items From ListBox!
A VB6 project has 2 Forms named frm1 & frm2. Both the Forms have a ListBox named ListBox1 & ListBox2 respectively. Assume that the ListBox in frm1 is empty. When a CommandButton is clicked in frm1, frm2 loads.

The ListBox in frm2 lists country names from a text file. Users can select multiple items from ListBox2. After selecting items from ListBox2, when a OK CommandButton in frm2 is clicked, 3 things happen:

1. frm2 unloads & frm1 gets activated
2. the selected items in ListBox2 get deleted
3. those deleted items get added to ListBox1 in frm1

This is how I am doing it:
VB Code:
[u]code in [i]frm2[/i][/u]Private Sub cmdOK_Click()    Dim i As Integer     For i = ListBox2.ListCount - 1 To 0 Step (-1)        If (ListBox2.Selected(i) = True) Then            [b][color=red]frm1[/color][/b][color=red][/color].ListBox1.AddItem ListBox2.List(i)            'MsgBox ListBox2.List(i)            ListBox2.RemoveItem (i)        End If    Next i     'MsgBox frm1.ListBox1.ListCount    Unload MeEnd Sub
The problem I am facing is the selected items in ListBox2 get deleted & frm2 also unloads but the items deleted from ListBox2 don't get added to ListBox1 which exists in frm1.

I even debugged the code by stepping over each & every line; the code flow turned out to be exactly what I wanted but I don't understand why the deleted items from ListBox2 aren't getting added to ListBox1.

In order to further debug the code, I added the 2 MsgBox lines which are commented. Now if I select say India, Japan & China from ListBox2 & click the OK CommandButton in frm2, then the first MsgBox, as expected, shows India, Japan & China. The second MsgBox also correctly shows the ListCount of ListBox1 as 3!

What am I doing wrong here?

This is how I am invoking frm2 when a CommandButton is clicked in frm1:
VB Code:
[u]code in [i]frm1[/i][/u]Private Sub cmdAdd_Click()    Dim frm As frm2    Set frm = New frm2    Call frm.ShowMe(Me)End Sub [u]code in [i]frm2[/i][/u]Private frmOwner As FormPublic Sub ShowMe(OwnerForm As Form)    Set frmOwner = OwnerForm    Me.Show vbModeless, frmOwner    frmOwner.Enabled = FalseEnd Sub
I also added this small code snippet in frm1 to further debug the app:
VB Code:
Private Sub Form_Activate()    MsgBox ListBox1.ListCount    MsgBox Me.ListBox1.ListCount    MsgBox frm1.ListBox1.ListCountEnd Sub
Strangely after selecting 3 items from ListBox2, when frm1 gets activated, the first 2 MsgBox's wrongly show the ListCount of ListBox1 as 0 but the third MsgBox correctly shows the ListCount of ListBox1 as 3!

Why this eccentricity?

Remove All Items In Listbox.
How can I remove all items in a text box, i'm guessing its going to use a loop.

Clearing Add/Remove Items
I am trying to make my own setup1.exe

I've been modifying the original setup1.vbp.

Most of it works fine.

When i install the program and remove it , the item is still visible in the Add/Remove Programs section.

Everything is removed except it is still visible in this.

Can anyone tell me how I can make it so these items are removed also.

Advanced thanks

Remove Items From Listbox
I need to remove items from the listbox after they have been entered.
the list looks like this:

Book (30)
Orange (20)
Blanket (-10)
Apple (0)

Is there any way to remove the negative values and the zero values.
(I mean the whole line Blanket (-10) and they are not always the same) Sample code please.
Tia
Spiritwolf

Remove Items From Listbox
I'm loading junk files into a listbox where the user can place checks in the ones he wants to delete. It works fine but how do I remove the ones he deleted from the listbox? I can't get RemoveItem to work. Here's the code I'm using to delete the selected files.

Dim i
For i = 0 To lstFoundFiles.ListCount - 1
If lstFoundFiles.Selected(i) Then
Kill lstFoundFiles.List(i)
End If
Next i

Remove Items From A File
How would I remove a specific string of words from a text file, and then put them back, in a specific location in that same file?

***---Remove Listbox Items---***
if i have a number of items in a list box lets say a 100 and i want to remove 50 from the middle so 25 to 75. So how can i delete those items fromt he listbox. Al of this would be in a command button

Remove Items From Listview?
Hi,

I have a listview which allows multiple selections. I want to place a button on the form which removes each selected item.

I'm having difficulty because VB renumbers each item index number as each item is removed. So item #2 which had an index of #2 now becomes #1. This would be no problem if the multiple selection was from item 1 to 5 where you could just loop through and remove index #1 5 times. But, what if the user selects items randomly?

Any help would be appreciated..

DAn

Remove Array Items?
Hi again,

I've just made a string array by "split".

I just wonder if there is any ready method to remove an item so the array will be shrinked, or should I have to do it by myself?

Thanks!

Remove Items From Listview In VB6
I have a listview1 control with 3 columns, CustId, CustName and CustContact. Each time I selected a row then clicked on the Command button to delete the selected row(s), it's not happening. Instead I got this error message "Element Not Found". I don't quite understand what it meant and how to get the deletion working. Could someone please point me to the right direction. Thanks.

Here is a my sample codes:
I am using Component Lib : MSCOMCTL.OCX (VB6)


Private Sub BtnSelectRemove_Click()

      'remove listitems from Attendance list
      Dim vclm As ColumnHeader
      Dim vitmx As ListItem
      Dim i As Integer
      
      With Me.ListAttendance
             For i = 1 To .ListItems.Count
                 If .ListItems(i).Selected = True Then
        .listitems.remove(.listitems(i))
                 End If
            Next
      End With

End Sub

Have a Good Day,

Thanks and Cheers,
Lennie

Edited by - Lennie on 2/9/2005 3:44:27 PM

List Box, Remove Items 1 By 1
I am using a progress bar with a list box. The plan was to have the progress bar move along as the items in the list box were deleted (the program has to go through other steps before removing an item, and this task can take a while to complete). Anyways, this is what I have to remove the items from my list box, however, it only seems to remove the even number items and leave other items in the list box:
Code:
For i = 0 To List1.ListCount - 1
    List1.RemoveItem i
Next i

Remove Items From List Box
why does when adding items to a list box all items are added according to index increment, but when items are removed only even items are removed????


thanks for your help

dave ...this is the code

Private Sub Command1_Click()
Dim Entry, i, Msg ' Declare variables.
Msg = "Choose OK to add 100 items to your list box."
MsgBox Msg ' Display message.
For i = 1 To 100 ' Count from 1 to 100.
Entry = "Entry " & i ' Create entry.
Debug.Print Entry & " "
List1.AddItem Entry ' Add the entry.

Next i
Msg = "Choose OK to remove every other entry."
MsgBox Msg ' Display message.
For i = 1 To List1.ListCount ' Determine how to


Debug.Print List1.ListIndex

Debug.Print List1.ListIndex
List1.RemoveItem (i)

Next i ' item.


Msg = "Choose OK to remove all items from the list box."
MsgBox Msg ' Display message.
List1.Clear ' Clear list box.

End Sub

Remove ListBox Items
Hi

Please tell me how to remove selected items from the listbox.

Wht i m using is here:

Dim i As Integer
i = 0
Dim Count As Integer
Count = lstAssignment.ListCount - 1
For i = 0 To lstAssignment.ListCount - 1
If lstAssignment.Selected(i) = True Then
lstAssignment.RemoveItem (i)
End If
Next i


it showing me an Invalid property array index

Please Help Me.

Thanx

Remove All Duplicated Items From A Listbox
i am filling a listbox with a lot of items then doing some stuff with that but then i want to delete all duplicated items. what is the best way because there will be a lot.

thanks

Remove Multiple Items From A Listbox
How can I remove multiple items from a listbox?

I have tried this, but it won't work....


Code:
Dim i As Integer

For i = 0 To Me.lstFiles.ListCount - 1
If Me.lstFiles.Selected(i) = True Then
Me.lstFiles.RemoveItem Me.lstFiles.List(i)
End If
Next i

Remove Multiple Items From Listbox
Hi,

I have a listbox which is multiple selection enabled and I have a button which removes all selected items by looping through like so:


Code:
Do While PlayList.SelectedIndex <> -1
PlayList.Items.RemoveAt(PlayList.SelectedIndex)
Loop
This works, the problem is I have another piece of code which is triggered by the selected index being changed. It checks the count of the listbox and if empty does one thing and if not does another.

The problem is the selected index changes before the item is removed which means that even when the list is empty the count shows one and the program takes the wrong path.

Can anyone help?

Thanks
Stephen Reid

Listbox And Remove Multiple Items
i have this code for loading and removing items from a list box. i am generating an error with my remove item statment. i want to add the item at position i to the correct list box and also delete the item at postion i from both boxes. how i generate an invalid procedure call a the first removeitem command in either statement.

dim x as interger
x = 4

If card1Value > card2Value Then
MsgBox "card1 bigger " & card1 & " " & card2
For I = 0 To X
MsgBox I
lstDeck1.AddItem lstDeck1.List(I)
lstDeck1.RemoveItem lstDeck1.List(I)
lstDeck1.AddItem lstDeck2.List(I)
lstDeck2.RemoveItem lstDeck2.List(I)

Next
Else
MsgBox "card2 bigger" & card1 & " " & card2
For I = 0 To X
MsgBox I
lstDeck2.AddItem lstDeck1.List(I)
lstDeck1.RemoveItem lstDeck1.List(I)
lstDeck2.AddItem lstDeck2.List(I)
lstDeck2.RemoveItem lstDeck2.List(I)
Next I


any thoughts?

How Can I Remove Checked Items In A Listbox?
Hi,

I have a ListBox1 with a checkbox style and a cmdbutton.
How can i remove only the checked items in the listbox1?

Thanks,

Warad
yes i searched before i asked

Remove Selected Items In The Listview.
How I can remove the selected items in the listview?


Code:
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems.Item(i).selected Then

'what should I put here

End If
Next i

Check Box To Remove Items From List?
I have made this progam that picks random things from two lists and displays them on a form. I was wondering if there is a way i can have it so when i check a check box labled one of the items in one of the lists will not show up anymore.

Remove Menu Items At Run Time
Hi, is it possible to remove items from menus added using the Menu Editor at run time?

Cheers

How To Remove Items From Listview Or Listbox ?
Hi all could any one show me i can delte item from both listview and listbox.Thanks

Remove Random Items From Listbox
Ok, I'm trying to remove 2 random items from a listbox at once. Then take the larger of the two randomly selected numbers and subtract the smaller from it. Then re-ad the ne number back into my listbox. This will repeat until only one number is left. Here's what i've got so far but I keep on getting error's.

Dim i As Integer
Dim Num As Integer
Dim Num1 As Integer
Dim j As Integer
Dim k As Integer
Dim f As Integer

Num = Round(Rnd * (List1.ListCount - 1), 0)
j = List1.List(Num)
Num1 = Round(Rnd * (List1.ListCount - 2), 0)
k = List1.List(Num1)

If j > k Then
f = j - k
ElseIf k > j Then
f = k - j
End If

For i = 1 To List1.ListCount
List1.RemoveItem (Num)
List1.RemoveItem (Num1)
List1.AddItem (f)
Next i


When I run this I get debug error 5 (Invaled procedure call or arguement) And it highlights "List1.RemoveItem (Num)" Any suggestions???

2 Listboxes-Remove Matching Items
VB Code:
'I searched and found this code that will copy all items from List1 to List2 if the'item isn't in List2.  What I'm trying to do is reverse it and Remove matching items'from List2 if they do exist in List1. 'Original Code  Dim i, j As Integer  Dim bMatch As Boolean  'this will take strings from list1 and add to list2  For i = 0 To List1.ListCount - 1    bMatch = False    For j = 0 To List2.ListCount - 1      If List1.List(i) = List2.List(j) Then        bMatch = True        Exit For      End If    Next j    'add list1 item to list2    If bMatch = False Then List2.AddItem List1.List(i)   Next i   'When I change it to remove the matching item it doesn't work   Dim i, j As Integer  Dim bMatch As Boolean  'this will take strings from list1 and add to list2  For i = 0 To List1.ListCount - 1    bMatch = False    For j = 0 To List2.ListCount - 1      If List1.List(i) = List2.List(j) Then        bMatch = True        Exit For      End If    Next j    'add list1 item to list2    If bMatch = True Then List2.RemoveItem List1.List(i)   Next i

Remove Items From Listbox....Resloved
Is there anybody knows how to remove items from a listbox with checkbox style?

e.g. I want to remove the first 3 items from the list so I select the first 3 items but my code just remove the first 2 items for me....and the third one is still in the list....

Please help


VB Code:
total = list1.ListCount    For i = 0 To total - 1        If list1.selected(i) Then            list1.RemoveItem list1.ItemData(i)        End If    Next

Disable Or Remove Datacombo Items
My project has 8 datacombo-boxes which are populated from the same list of data.
Is there a way to temporarily either disable/remove items from the list as they are used in each box - I need to ensure that each box contains a unique value from those available in the list presented.

Remove Matching Items From Listview
I'm using a listview to load a list of email address's. What I'm trying to do is remove all address's from a selected domain using a GetExtension Sub to get the domain name. The problem is when I call the sub RemoveDomain() it removes the address I clicked on and all that come before it leaving those after it and not removing all from that domain. First I'm geting the domain extension in lblExt.Caption and that works fine. I'm trying to match that with the selected item in Listview and remove all those. I hope I've made this clear what I'm trying to do. Here's what I have so far.

Public Function GetExtension(ByVal p_strFileName As String) As String
If InStr(p_strFileName, "@") = 0 Then Exit Function

GetExtension = Mid(p_strFileName, InStrRev(p_strFileName, "@") + 1)
End Function

Private Sub RemoveDomain()
On Error Resume Next
Dim x As Long
x = 1
While x < ListView1.ListItems.Count + 1
Debug.Print x

If GetExtension(ListView1.SelectedItem) = lblExt.Caption Then
ListView1.ListItems.Remove x
Else
x = x + 1
End If
Wend

End Sub

Remove Multiple Items From ListView
I've got a ListView control with the MultiSelect property set to True and would like to remove all of the selected items only. I've looked at some of the threads concerning this issue but am still having trouble. I can remove a single selected item but not all of the selected items. My code is as follows:


Code:
Private Sub cmdRemove_Click()

Dim I As Integer

For I = 1 To lstPlot.ListItems.Count
If lstPlot.ListItems(I).Selected = True Then
lstPlot.ListItems.Remove (I)
End If
Next I

End Sub


What am I missing?

Thanks for your help!

How Do I Remove Empty Items From A List Box?
How do i remove empty items from a list box?

Thanx

Add / Remove Menu Items At Runtime
How do I add and remove items in a menu at runtime?

Thanks

Howto Remove All Items From A Combobox
How do I remove al items from a combobox but leave the comboboxes text intact...

Also it should not create an error if there are no items in the list...

Remove Non Selected Listbox Items
I have a list box which allows you to select multiple items. I'd like to then have the option of removing all items that are not selected.

Here is what I have...


Code:

'remove any non selected items
For i = 0 To lstOccup.Items.Count - 1
found = False
For j = 0 To lstOccup.SelectedItems.Count - 1
If lstOccup.Items(i).ToString = lstOccup.SelectedItems(j).ToString Then
found = True
End If
Next
If found = False Then
lstOccup.Items.RemoveAt(i)
End If
Next



This doesn't work because once I use RemoveAt it means the for loops no longer work.

Remove SysMenu Items (right Click In Taskbar)
Need help...

I've subclassed the system menu (the right click thing that pops up in the taskbar) and removed all the items and put my own in, but I can't seem to delete the inherent separator... so there is this ugly separator at the top (not really separating anything), I've tried removing it using MF_BYCOMMAND and MF_BYPOSITION in the DeleteMenu function... nothing

any one have any ideas?
gR

Remove Items With A Special Text, Listbox
Lets say listbox goes like this

joe4 goes
joe goes
joe4 jumps
joe4 hops

How do I delete all of the lines that say joe4? And they are random everytime.

Remove Or Hide Double Items In Listbox
Hi,

Got a small problem (I hope)

Can Anyone tell me how to remove or hide double items from a listbox?

This is what I already have:
CODEPrivate Sub Combo1_Click()
    List1.Clear

    Set rs = New Recordset

    rs.Open "SELECT DISTINCT * FROM POSTCODE WHERE GEMEENTE = '" & Combo1.Text & "'", cn, adOpenDynamic

    Do Until rs.EOF
        List1.AddItem rs!Plaats  '<----
        rs.MoveNext
    Loop

    rs.Close
    Set rs = Nothing
End Sub

Remove Multiple Listbox Items And Change Original
Ok, I have 2 list boxes in my form and by double clicking on one, it will add it to the other side, but what I want it to do is when it is double clicked, it will check if there is an item by the same name in the other, and if there is, not add a new item, but change the existing one by adding a number in front of it. Say I have a list box with the following items: Apple, Bannanna, Coke, Sprite, and Pepsi. When one of those is double clicked, it will check to see if there is already an item by that name in the second listbox, and if there is, change the first part or it to 2 Bannana or 3 Bannana if there is already 2. I have a feeling the way to go would be to use the mid function to check the beginning for the number and change that, but I dont know how to do that. I have found plenty of ways to check to see if there is an item by the same name, but I havnt found one that will change the original if there is. Any help would be appreciated.

Compare 2 Listbox And Remove Doplicate Items From One Of Them - Need A Hand Or Two..
looking for the fastest way to compare 2 listboxes and remove doplicate items from one of them

Thanks in advanced

Access 2002 - Remove Multiple Items In A List Box (Resolved)
In Access 2002, does anyone know the best method for removing selected items from a Multi-Select ListBox?

On my Form, I have one Multi-Select ListBox and one button that allows the user to delete the selected item(s) from
the ListBox. In my "btnRemoveTo_Click" event, I have tried the following 2 methods to remove the selected items from the list box. However, in my looping routine, when I issue the .RemoveItem command, all the items that were selected in the Multi-Select list box, become unselected, thereby leaving no items selected. For instance, if the user has 5 items selected, the first time the .RemoveItem code is issued the first item selected is Removed from the list box, but after that, all the items become deselected, leaving me with no items selected - therefore no other items are removed.

Code:Private Sub btnRemoveTo_Click()
Dim vItem As Variant, iRow As Integer
' Remove all the items selected from the list box.
With Me
    If .listSendTo.ItemsSelected.Count = 0 Then
        Exit Sub
    Else
        ' METHOD #1
        For iRow = .listSendTo.ListCount - 1 To 0 Step -1
            If .listSendTo.Selected(iRow) Then .listSendTo.RemoveItem iRow
        Next

        ' METHOD #2
        'For Each vItem In .listSendTo.ItemsSelected
        ' .listSendTo.RemoveItem vItem
        'Next
    End If
End With

End Sub


edit:: marked as resolved.



Edited by - Metallisoft on 5/19/2004 4:24:24 PM

Copyright © 2005-08 www.BigResource.com, All rights reserved