hi guyzz i wanted to remove item in the lisview using the for each
i want to delete multiple item with similar field in the listview.

any help.. for this problem..
it could be possible ?


i have here code but it delete only selected item in the listview.
(ListView1.ListItems.Remove (ListView1.SelectedItem.Index) )

hi sierrainfo. thx for the reply.. i think it didn't help me ^_^.. all my form using listview.
and have many column with same data.

about my thread(the first one).. is this possible in vb.
any ways for this...


in my recordset i load the data in the listview but the user can also delete it using their unique keys..

hope anyone can suggest.

you can easily remove items which you need, but you have to select items which are need to remove.

U need not select the items to remove them.

Loop thru all the items in the listview with index for tracking the item against the loop variable. compare the values of each item and delete which ever match the criteria. when deletion occurs the indices of the items following the deleted item will change. hence keep track of the last index.

If still problem persists then i will try to help u with some sample code.


Regards
Shaik Akthar

hi aktharshaik.. thx for the reply

i have my code here but i cant continue .. plss help

for each li in listview1.listitem
if li.text = text1.text then
............remove..()
end if
next


plss help me.. i almost tried all but cant now the code to be put that well delete when matching in the condition..

Try this code

Dim iVal As Integer
    Dim lCount As Integer

    lCount = li.ListItems.Count
    For iVal = 1 To lCount
        If iVal > lCount Then Exit For
        'If u want to compare to the First Column
        If Trim(li.ListItems(iVal).Text) = Trim(Text1.Text) Then
            li.ListItems.Remove (iVal)
            iVal = iVal - 1
            lCount = lCount - 1
        End If

''If u want to compare to the other Column use SubItems
''SubItems(1) is 2nd col, SubItems(2) is 3rd col and so on...
'        If Trim(li.ListItems(iVal).SubItems(1)) = Trim(Text1.Text) Then
'            li.ListItems.Remove (iVal)
'            iVal = iVal - 1
'            lCount = lCount - 1
'        End If
 
   Next

also while comparing if u don't want it to be case sensitive use the UCASE() function

If UCase(Trim(li.ListItems(iVal).Text)) = UCase(Trim(Text1.Text)) Then

Regards
Shaik Akthar

if you just remove the data in the listview, and when your listview was not bound in the database, everytime you load the form the data you remove will back again since you dont remove it in the database... how about delete it from the database then reload the loading of your listview.

The Logic for the removal of the related records in the database can be written just before the Remove event of the ListView. After all matched Items are done, U will have the database updated as well as the ListView and I think there is no need to Reload the ListView, which involved again querying the DB. Alternatively it can be done to re-confirm if the records are really deleted from the DB or not.

Regards
Shaik Akthar

hi thx for the aktharshaik...

thx you so much..

this is what i did on mine..

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim a As String

If KeyCode = vbKeyDelete Then

        If listview1.SelectedItem = True Then

            a = MsgBox("Are you sure you want to delete?", vbInformation + vbYesNo, "REQUESTING CONFIRMATION")

                If vbYes Then

                    listview1.ListItems.Remove (listview1.SelectedItem.Index)

                End If

        End If

end if
end sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.