I have the following code which takes the selected items in a listbox and removes them from a list. As you can see, I call Dict.Remove for each individual selected object.
I feel there will be a "cleaner" way to do this using predicates or LINQ. I have tried searching the 'net but haven't found anything to do what I want. i.e. Dict.RemoveList(Listbox1.SelectedItems) type of thing.
I feel there will be a "cleaner" way to do this using predicates or LINQ. I have tried searching the 'net but haven't found anything to do what I want. i.e. Dict.RemoveList(Listbox1.SelectedItems) type of thing.
vb.net Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click If ListBox1.SelectedIndices.Count > 0 Then Dim sStr As String = "Are you sure you want to delete the" & vbCrLf & "following item(s) from the database?" & vbCrLf & vbCrLf For Each obj As Object In ListBox1.SelectedItems sStr += obj.ToString & vbCrLf Next Dim Reply As System.Windows.Forms.DialogResult = MessageBox.Show(sStr, "Delete entries", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If Reply = Windows.Forms.DialogResult.Yes Then 'take the count of entries in Dict Dim iDictWords As Integer = 0 iDictWords = Dict.Count 'remove the lines from Dict For Each obj As Object In ListBox1.SelectedItems Dict.Remove(obj.ToString) Next 'rewrite file to delete entries 'TODO remove the items from the listbox list MsgBox((iDictWords - Dict.Count).ToString & " entries deleted") End If End If End Sub