Hi guys I am trying to implement this bit of code in a BGW have it in a Sub now but need it in BGW

Sub Code Code:
  1. If Not String.IsNullOrEmpty(CStr(Dialog1.ComboBox3.SelectedItem)) Then
  2. Dim tName As String = Dialog1.ComboBox3.SelectedItem.ToString
  3.             For Each item As String In Dialog1.CheckedListBox1.CheckedItems()
  4.                 For i = table.Rows.Count - 1 To 0 Step -1
  5.                     If (table.Rows(i)(tName)).Equals(item) Then
  6.                         table.Rows.RemoveAt(i)
  7.                     End If
  8.                 Next
  9.             Next
  10.         End If

I have a button that shows a dialogbox that contains various combo, text and checklist boxesx based on the selectedindex of the comboBox a checklist box is populated with all the unique fields in that column


What would be the most "proper" way to do this? This is what i have so far:

Sub Code:
  1. Private Sub DelRecs()
  2.         If Not String.IsNullOrEmpty(CStr(Dialog1.ComboBox3.SelectedItem)) Then
  3.             Dim tName As String = CStr(Dialog1.ComboBox3.SelectedItem)
  4.             For Each item As String In Dialog1.CheckedListBox1.CheckedItems()
  5.                 list.Add(item)
  6.             Next
  7.             BackgroundWorker5.RunWorkerAsync()
  8.         End If
  9.     End Sub

bgw Code:
  1. Private Sub BackgroundWorker5_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker5.DoWork
  2.         Dim worker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker)
  3.         For Each item As String In list
  4.             For i = table.Rows.Count - 1 To 0 Step -1
  5.                 If (table.Rows(i)(tName)).Equals(item) Then
  6.                     table.Rows.RemoveAt(i)
  7.                 End If
  8.             Next
  9.         Next
  10.     End Sub

declarations Code:
  1. Dim item As String
  2.     Dim list As New List(Of String)
  3.     Dim tName As String

I am really confused as I have something very similiar in another BGW and it works fine

But something tells me I am not doing this properly

Thanks